Chore: Remove context.TODO() from services (#42555)

* Remove context.TODO() from services

* Fix live test
This commit is contained in:
idafurjes
2021-12-20 17:05:33 +01:00
committed by GitHub
parent 6f8e651cdb
commit ff3cf94b56
23 changed files with 78 additions and 75 deletions
@@ -39,7 +39,7 @@ func TestEngineTimeouts(t *testing.T) {
engine.evalHandler = evalHandler
engine.resultHandler = resultHandler
err := engine.processJobWithRetry(context.TODO(), job)
err := engine.processJobWithRetry(context.Background(), job)
require.Nil(t, err)
require.Equal(t, true, evalHandler.EvalSucceed)
+3 -3
View File
@@ -124,7 +124,7 @@ func TestEngineProcessJob(t *testing.T) {
evalHandler := NewFakeEvalHandler(0)
engine.evalHandler = evalHandler
err := engine.processJobWithRetry(context.TODO(), job)
err := engine.processJobWithRetry(context.Background(), job)
require.Nil(t, err)
require.Equal(t, expectedAttempts, evalHandler.CallNb)
})
@@ -134,7 +134,7 @@ func TestEngineProcessJob(t *testing.T) {
evalHandler := NewFakeEvalHandler(1)
engine.evalHandler = evalHandler
err := engine.processJobWithRetry(context.TODO(), job)
err := engine.processJobWithRetry(context.Background(), job)
require.Nil(t, err)
require.Equal(t, expectedAttempts, evalHandler.CallNb)
})
@@ -144,7 +144,7 @@ func TestEngineProcessJob(t *testing.T) {
evalHandler := NewFakeEvalHandler(expectedAttempts)
engine.evalHandler = evalHandler
err := engine.processJobWithRetry(context.TODO(), job)
err := engine.processJobWithRetry(context.Background(), job)
require.Nil(t, err)
require.Equal(t, expectedAttempts, evalHandler.CallNb)
})
+1 -1
View File
@@ -15,7 +15,7 @@ import (
)
func TestStateIsUpdatedWhenNeeded(t *testing.T) {
ctx := NewEvalContext(context.TODO(), &Rule{Conditions: []Condition{&conditionStub{firing: true}}}, &validations.OSSPluginRequestValidator{})
ctx := NewEvalContext(context.Background(), &Rule{Conditions: []Condition{&conditionStub{firing: true}}}, &validations.OSSPluginRequestValidator{})
t.Run("ok -> alerting", func(t *testing.T) {
ctx.PrevAlertState = models.AlertStateOK
+14 -14
View File
@@ -25,7 +25,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
handler := NewEvalHandler(nil)
t.Run("Show return triggered with single passing condition", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{&conditionStub{
firing: true,
}},
@@ -37,7 +37,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
})
t.Run("Show return triggered with single passing condition2", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{&conditionStub{firing: true, operator: "and"}},
}, &validations.OSSPluginRequestValidator{})
@@ -47,7 +47,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
})
t.Run("Show return false with not passing asdf", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{
&conditionStub{firing: true, operator: "and", matches: []*EvalMatch{{}, {}}},
&conditionStub{firing: false, operator: "and"},
@@ -60,7 +60,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
})
t.Run("Show return true if any of the condition is passing with OR operator", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{
&conditionStub{firing: true, operator: "and"},
&conditionStub{firing: false, operator: "or"},
@@ -73,7 +73,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
})
t.Run("Show return false if any of the condition is failing with AND operator", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{
&conditionStub{firing: true, operator: "and"},
&conditionStub{firing: false, operator: "and"},
@@ -86,7 +86,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
})
t.Run("Show return true if one condition is failing with nested OR operator", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{
&conditionStub{firing: true, operator: "and"},
&conditionStub{firing: true, operator: "and"},
@@ -100,7 +100,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
})
t.Run("Show return false if one condition is passing with nested OR operator", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{
&conditionStub{firing: true, operator: "and"},
&conditionStub{firing: false, operator: "and"},
@@ -114,7 +114,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
})
t.Run("Show return false if a condition is failing with nested AND operator", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{
&conditionStub{firing: true, operator: "and"},
&conditionStub{firing: false, operator: "and"},
@@ -128,7 +128,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
})
t.Run("Show return true if a condition is passing with nested OR operator", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{
&conditionStub{firing: true, operator: "and"},
&conditionStub{firing: false, operator: "or"},
@@ -142,7 +142,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
})
t.Run("Should return false if no condition is firing using OR operator", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{
&conditionStub{firing: false, operator: "or"},
&conditionStub{firing: false, operator: "or"},
@@ -157,7 +157,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
// FIXME: What should the actual test case name be here?
t.Run("Should not return NoDataFound if all conditions have data and using OR", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{
&conditionStub{operator: "or", noData: false},
&conditionStub{operator: "or", noData: false},
@@ -170,7 +170,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
})
t.Run("Should return NoDataFound if one condition has no data", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{
&conditionStub{operator: "and", noData: true},
},
@@ -182,7 +182,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
})
t.Run("Should return no data if at least one condition has no data and using AND", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{
&conditionStub{operator: "and", noData: true},
&conditionStub{operator: "and", noData: false},
@@ -194,7 +194,7 @@ func TestAlertingEvaluationHandler(t *testing.T) {
})
t.Run("Should return no data if at least one condition has no data and using OR", func(t *testing.T) {
context := NewEvalContext(context.TODO(), &Rule{
context := NewEvalContext(context.Background(), &Rule{
Conditions: []Condition{
&conditionStub{operator: "or", noData: true},
&conditionStub{operator: "or", noData: false},
@@ -72,7 +72,7 @@ func TestWhenAlertManagerShouldNotify(t *testing.T) {
evalContext.Rule.State = tc.newState
res := am.ShouldNotify(context.TODO(), evalContext, &models.AlertNotificationState{})
res := am.ShouldNotify(context.Background(), evalContext, &models.AlertNotificationState{})
if res != tc.expect {
t.Errorf("got %v expected %v", res, tc.expect)
}
@@ -257,7 +257,7 @@ func TestSendSlackRequest(t *testing.T) {
require.NoError(t, err)
slackNotifier := not.(*SlackNotifier)
err = slackNotifier.sendRequest(context.TODO(), []byte("test"))
err = slackNotifier.sendRequest(context.Background(), []byte("test"))
if !test.expectError {
require.NoError(tt, err)
} else {