@@ -29,11 +29,11 @@ func TestDetectorNoJobs(t *testing.T) {
29
29
t .Parallel ()
30
30
31
31
var (
32
- ctx , cancel = context . WithCancel ( testutil .Context (t , testutil .WaitLong ) )
33
- db , pubsub = dbtestutil .NewDB (t )
34
- log = slogtest .Make (t , nil )
35
- tickCh = make (chan time.Time )
36
- statsCh = make (chan unhanger.Stats )
32
+ ctx = testutil .Context (t , testutil .WaitLong )
33
+ db , pubsub = dbtestutil .NewDB (t )
34
+ log = slogtest .Make (t , nil )
35
+ tickCh = make (chan time.Time )
36
+ statsCh = make (chan unhanger.Stats )
37
37
)
38
38
39
39
detector := unhanger .New (ctx , db , pubsub , log , tickCh ).WithStatsChannel (statsCh )
@@ -44,19 +44,19 @@ func TestDetectorNoJobs(t *testing.T) {
44
44
require .NoError (t , stats .Error )
45
45
require .Empty (t , stats .HungJobIDs )
46
46
47
- cancel ()
47
+ detector . Close ()
48
48
detector .Wait ()
49
49
}
50
50
51
51
func TestDetectorNoHungJobs (t * testing.T ) {
52
52
t .Parallel ()
53
53
54
54
var (
55
- ctx , cancel = context . WithCancel ( testutil .Context (t , testutil .WaitLong ) )
56
- db , pubsub = dbtestutil .NewDB (t )
57
- log = slogtest .Make (t , nil )
58
- tickCh = make (chan time.Time )
59
- statsCh = make (chan unhanger.Stats )
55
+ ctx = testutil .Context (t , testutil .WaitLong )
56
+ db , pubsub = dbtestutil .NewDB (t )
57
+ log = slogtest .Make (t , nil )
58
+ tickCh = make (chan time.Time )
59
+ statsCh = make (chan unhanger.Stats )
60
60
)
61
61
62
62
// Insert some jobs that are running and haven't been updated in a while,
@@ -91,19 +91,19 @@ func TestDetectorNoHungJobs(t *testing.T) {
91
91
require .NoError (t , stats .Error )
92
92
require .Empty (t , stats .HungJobIDs )
93
93
94
- cancel ()
94
+ detector . Close ()
95
95
detector .Wait ()
96
96
}
97
97
98
98
func TestDetectorHungWorkspaceBuild (t * testing.T ) {
99
99
t .Parallel ()
100
100
101
101
var (
102
- ctx , cancel = context . WithCancel ( testutil .Context (t , testutil .WaitLong ) )
103
- db , pubsub = dbtestutil .NewDB (t )
104
- log = slogtest .Make (t , nil )
105
- tickCh = make (chan time.Time )
106
- statsCh = make (chan unhanger.Stats )
102
+ ctx = testutil .Context (t , testutil .WaitLong )
103
+ db , pubsub = dbtestutil .NewDB (t )
104
+ log = slogtest .Make (t , nil )
105
+ tickCh = make (chan time.Time )
106
+ statsCh = make (chan unhanger.Stats )
107
107
)
108
108
109
109
var (
@@ -195,19 +195,19 @@ func TestDetectorHungWorkspaceBuild(t *testing.T) {
195
195
require .NoError (t , err )
196
196
require .Equal (t , expectedWorkspaceBuildState , build .ProvisionerState )
197
197
198
- cancel ()
198
+ detector . Close ()
199
199
detector .Wait ()
200
200
}
201
201
202
202
func TestDetectorHungWorkspaceBuildNoOverrideState (t * testing.T ) {
203
203
t .Parallel ()
204
204
205
205
var (
206
- ctx , cancel = context . WithCancel ( testutil .Context (t , testutil .WaitLong ) )
207
- db , pubsub = dbtestutil .NewDB (t )
208
- log = slogtest .Make (t , nil )
209
- tickCh = make (chan time.Time )
210
- statsCh = make (chan unhanger.Stats )
206
+ ctx = testutil .Context (t , testutil .WaitLong )
207
+ db , pubsub = dbtestutil .NewDB (t )
208
+ log = slogtest .Make (t , nil )
209
+ tickCh = make (chan time.Time )
210
+ statsCh = make (chan unhanger.Stats )
211
211
)
212
212
213
213
var (
@@ -300,19 +300,19 @@ func TestDetectorHungWorkspaceBuildNoOverrideState(t *testing.T) {
300
300
require .NoError (t , err )
301
301
require .Equal (t , expectedWorkspaceBuildState , build .ProvisionerState )
302
302
303
- cancel ()
303
+ detector . Close ()
304
304
detector .Wait ()
305
305
}
306
306
307
307
func TestDetectorHungWorkspaceBuildNoOverrideStateIfNoExistingBuild (t * testing.T ) {
308
308
t .Parallel ()
309
309
310
310
var (
311
- ctx , cancel = context . WithCancel ( testutil .Context (t , testutil .WaitLong ) )
312
- db , pubsub = dbtestutil .NewDB (t )
313
- log = slogtest .Make (t , nil )
314
- tickCh = make (chan time.Time )
315
- statsCh = make (chan unhanger.Stats )
311
+ ctx = testutil .Context (t , testutil .WaitLong )
312
+ db , pubsub = dbtestutil .NewDB (t )
313
+ log = slogtest .Make (t , nil )
314
+ tickCh = make (chan time.Time )
315
+ statsCh = make (chan unhanger.Stats )
316
316
)
317
317
318
318
var (
@@ -376,19 +376,19 @@ func TestDetectorHungWorkspaceBuildNoOverrideStateIfNoExistingBuild(t *testing.T
376
376
require .NoError (t , err )
377
377
require .Equal (t , expectedWorkspaceBuildState , build .ProvisionerState )
378
378
379
- cancel ()
379
+ detector . Close ()
380
380
detector .Wait ()
381
381
}
382
382
383
383
func TestDetectorHungOtherJobTypes (t * testing.T ) {
384
384
t .Parallel ()
385
385
386
386
var (
387
- ctx , cancel = context . WithCancel ( testutil .Context (t , testutil .WaitLong ) )
388
- db , pubsub = dbtestutil .NewDB (t )
389
- log = slogtest .Make (t , nil )
390
- tickCh = make (chan time.Time )
391
- statsCh = make (chan unhanger.Stats )
387
+ ctx = testutil .Context (t , testutil .WaitLong )
388
+ db , pubsub = dbtestutil .NewDB (t )
389
+ log = slogtest .Make (t , nil )
390
+ tickCh = make (chan time.Time )
391
+ statsCh = make (chan unhanger.Stats )
392
392
)
393
393
394
394
var (
@@ -467,7 +467,7 @@ func TestDetectorHungOtherJobTypes(t *testing.T) {
467
467
require .Contains (t , job .Error .String , "Build has been detected as hung" )
468
468
require .False (t , job .ErrorCode .Valid )
469
469
470
- cancel ()
470
+ detector . Close ()
471
471
detector .Wait ()
472
472
}
473
473
@@ -506,11 +506,11 @@ func TestDetectorPushesLogs(t *testing.T) {
506
506
t .Parallel ()
507
507
508
508
var (
509
- ctx , cancel = context . WithCancel ( testutil .Context (t , testutil .WaitLong ) )
510
- db , pubsub = dbtestutil .NewDB (t )
511
- log = slogtest .Make (t , nil )
512
- tickCh = make (chan time.Time )
513
- statsCh = make (chan unhanger.Stats )
509
+ ctx = testutil .Context (t , testutil .WaitLong )
510
+ db , pubsub = dbtestutil .NewDB (t )
511
+ log = slogtest .Make (t , nil )
512
+ tickCh = make (chan time.Time )
513
+ statsCh = make (chan unhanger.Stats )
514
514
)
515
515
516
516
var (
@@ -608,7 +608,7 @@ func TestDetectorPushesLogs(t *testing.T) {
608
608
require .NoError (t , err )
609
609
require .Len (t , logs , c .preLogCount + len (unhanger .HungJobLogMessages ))
610
610
611
- cancel ()
611
+ detector . Close ()
612
612
detector .Wait ()
613
613
})
614
614
}
0 commit comments