@@ -22,6 +22,7 @@ import (
22
22
// TestDeadlockDetection verifies that if the agent is stuck in "WaitAllRsMembersUp" phase (started > 15 seconds ago)
23
23
// then the function returns "ready"
24
24
func TestDeadlockDetection (t * testing.T ) {
25
+ ctx := context .Background ()
25
26
type TestConfig struct {
26
27
conf config.Config
27
28
isErrorExpected bool
@@ -108,7 +109,7 @@ func TestDeadlockDetection(t *testing.T) {
108
109
for testName , _ := range tests {
109
110
testConfig := tests [testName ]
110
111
t .Run (testName , func (t * testing.T ) {
111
- ready , err := isPodReady (testConfig .conf )
112
+ ready , err := isPodReady (ctx , testConfig .conf )
112
113
if testConfig .isErrorExpected {
113
114
assert .Error (t , err )
114
115
} else {
@@ -241,8 +242,9 @@ func TestObtainingCurrentStep(t *testing.T) {
241
242
// In this case, the Readiness Probe needs to return Ready and let the StatefulSet Controller to proceed
242
243
// with the Pod rollout.
243
244
func TestReadyWithWaitForCorrectBinaries (t * testing.T ) {
245
+ ctx := context .Background ()
244
246
c := testConfigWithMongoUp ("testdata/health-status-ok-with-WaitForCorrectBinaries.json" , time .Second * 30 )
245
- ready , err := isPodReady (c )
247
+ ready , err := isPodReady (ctx , c )
246
248
247
249
assert .True (t , ready )
248
250
assert .NoError (t , err )
@@ -254,26 +256,28 @@ func TestReadyWithWaitForCorrectBinaries(t *testing.T) {
254
256
// (as Agent doesn't marks all the step statuses finished when it reaches the goal) but this doesn't affect the result
255
257
// as the whole plan is complete already
256
258
func TestHeadlessAgentHasntReachedGoal (t * testing.T ) {
259
+ ctx := context .Background ()
257
260
t .Setenv (headlessAgent , "true" )
258
261
c := testConfig ("testdata/health-status-ok.json" )
259
262
c .ClientSet = fake .NewSimpleClientset (testdata .TestPod (c .Namespace , c .Hostname ), testdata .TestSecret (c .Namespace , c .AutomationConfigSecretName , 6 ))
260
- ready , err := isPodReady (c )
263
+ ready , err := isPodReady (ctx , c )
261
264
assert .False (t , ready )
262
265
assert .NoError (t , err )
263
- thePod , _ := c .ClientSet .CoreV1 ().Pods (c .Namespace ).Get (context . TODO () , c .Hostname , metav1.GetOptions {})
266
+ thePod , _ := c .ClientSet .CoreV1 ().Pods (c .Namespace ).Get (ctx , c .Hostname , metav1.GetOptions {})
264
267
assert .Equal (t , map [string ]string {"agent.mongodb.com/version" : "5" }, thePod .Annotations )
265
268
}
266
269
267
270
// TestHeadlessAgentReachedGoal verifies that the probe reports "true" if the config version is equal to the
268
271
// last achieved version of the Agent
269
272
func TestHeadlessAgentReachedGoal (t * testing.T ) {
273
+ ctx := context .Background ()
270
274
t .Setenv (headlessAgent , "true" )
271
275
c := testConfig ("testdata/health-status-ok.json" )
272
276
c .ClientSet = fake .NewSimpleClientset (testdata .TestPod (c .Namespace , c .Hostname ), testdata .TestSecret (c .Namespace , c .AutomationConfigSecretName , 5 ))
273
- ready , err := isPodReady (c )
277
+ ready , err := isPodReady (ctx , c )
274
278
assert .True (t , ready )
275
279
assert .NoError (t , err )
276
- thePod , _ := c .ClientSet .CoreV1 ().Pods (c .Namespace ).Get (context . TODO () , c .Hostname , metav1.GetOptions {})
280
+ thePod , _ := c .ClientSet .CoreV1 ().Pods (c .Namespace ).Get (ctx , c .Hostname , metav1.GetOptions {})
277
281
assert .Equal (t , map [string ]string {"agent.mongodb.com/version" : "5" }, thePod .Annotations )
278
282
}
279
283
0 commit comments