@@ -171,22 +171,24 @@ func TestCheckForUpgradesScheduler(t *testing.T) {
171171 const testUpgradeCheckURL = "http://localhost:8080"
172172
173173 t .Run ("panic from checkForUpgrades doesn't bubble up" , func (t * testing.T ) {
174- done := make (chan bool , 1 )
174+ ctx , cancel := context .WithCancel (context .Background ())
175+ defer cancel ()
176+
175177 // capture logs
176178 var calls []string
177- logging .SetLogFunc ( 1 , func (input genericr.Entry ) {
179+ ctx = logging .NewContext ( ctx , genericr . New ( func (input genericr.Entry ) {
178180 calls = append (calls , input .Message )
179- })
181+ }))
180182
181183 // A panicking call
182184 funcFoo = func () (* http.Response , error ) {
183185 panic (fmt .Errorf ("oh no!" ))
184186 }
185187
186- go CheckForUpgradesScheduler (done , "4.7.3" , testUpgradeCheckURL , fakeClient , cfg , false ,
188+ go CheckForUpgradesScheduler (ctx , "4.7.3" , testUpgradeCheckURL , fakeClient , cfg , false ,
187189 & MockCacheClient {works : true })
188190 time .Sleep (1 * time .Second )
189- done <- true
191+ cancel ()
190192
191193 // Sleeping leads to some non-deterministic results, but we expect at least 1 execution
192194 // plus one log for the failure to apply the configmap
@@ -195,32 +197,36 @@ func TestCheckForUpgradesScheduler(t *testing.T) {
195197 })
196198
197199 t .Run ("cache sync fail leads to log and exit" , func (t * testing.T ) {
198- done := make (chan bool , 1 )
200+ ctx , cancel := context .WithCancel (context .Background ())
201+ defer cancel ()
202+
199203 // capture logs
200204 var calls []string
201- logging .SetLogFunc ( 1 , func (input genericr.Entry ) {
205+ ctx = logging .NewContext ( ctx , genericr . New ( func (input genericr.Entry ) {
202206 calls = append (calls , input .Message )
203- })
207+ }))
204208
205209 // Set loop time to 1s and sleep for 2s before sending the done signal -- though the cache sync
206210 // failure will exit the func before the sleep ends
207211 upgradeCheckPeriod = 1 * time .Second
208- go CheckForUpgradesScheduler (done , "4.7.3" , testUpgradeCheckURL , fakeClient , cfg , false ,
212+ go CheckForUpgradesScheduler (ctx , "4.7.3" , testUpgradeCheckURL , fakeClient , cfg , false ,
209213 & MockCacheClient {works : false })
210214 time .Sleep (2 * time .Second )
211- done <- true
215+ cancel ()
212216
213217 assert .Assert (t , len (calls ) == 1 )
214218 assert .Equal (t , calls [0 ], `unable to sync cache for upgrade check` )
215219 })
216220
217221 t .Run ("successful log each loop, ticker works" , func (t * testing.T ) {
218- done := make (chan bool , 1 )
222+ ctx , cancel := context .WithCancel (context .Background ())
223+ defer cancel ()
224+
219225 // capture logs
220226 var calls []string
221- logging .SetLogFunc ( 1 , func (input genericr.Entry ) {
227+ ctx = logging .NewContext ( ctx , genericr . New ( func (input genericr.Entry ) {
222228 calls = append (calls , input .Message )
223- })
229+ }))
224230
225231 // A successful call
226232 funcFoo = func () (* http.Response , error ) {
@@ -233,10 +239,10 @@ func TestCheckForUpgradesScheduler(t *testing.T) {
233239
234240 // Set loop time to 1s and sleep for 2s before sending the done signal
235241 upgradeCheckPeriod = 1 * time .Second
236- go CheckForUpgradesScheduler (done , "4.7.3" , testUpgradeCheckURL , fakeClient , cfg , false ,
242+ go CheckForUpgradesScheduler (ctx , "4.7.3" , testUpgradeCheckURL , fakeClient , cfg , false ,
237243 & MockCacheClient {works : true })
238244 time .Sleep (2 * time .Second )
239- done <- true
245+ cancel ()
240246
241247 // Sleeping leads to some non-deterministic results, but we expect at least 2 executions
242248 // plus one log for the failure to apply the configmap
0 commit comments