1
- package reaper_test
1
+ package jobreaper_test
2
2
3
3
import (
4
4
"context"
@@ -20,9 +20,9 @@ import (
20
20
"github.com/coder/coder/v2/coderd/database/dbauthz"
21
21
"github.com/coder/coder/v2/coderd/database/dbgen"
22
22
"github.com/coder/coder/v2/coderd/database/dbtestutil"
23
+ "github.com/coder/coder/v2/coderd/jobreaper"
23
24
"github.com/coder/coder/v2/coderd/provisionerdserver"
24
25
"github.com/coder/coder/v2/coderd/rbac"
25
- "github.com/coder/coder/v2/coderd/reaper"
26
26
"github.com/coder/coder/v2/provisionersdk"
27
27
"github.com/coder/coder/v2/testutil"
28
28
)
@@ -49,10 +49,10 @@ func jobLogMessages(jobType jobType, threshold float64) []string {
49
49
// reapParamsFromJob determines the type and threshold for a job being reaped
50
50
func reapParamsFromJob (job database.ProvisionerJob ) (jobType , float64 ) {
51
51
jobType := hungJobType
52
- threshold := reaper .HungJobDuration .Minutes ()
52
+ threshold := jobreaper .HungJobDuration .Minutes ()
53
53
if ! job .StartedAt .Valid {
54
54
jobType = notStartedJobType
55
- threshold = reaper .NotStartedTimeElapsed .Minutes ()
55
+ threshold = jobreaper .NotStartedTimeElapsed .Minutes ()
56
56
}
57
57
return jobType , threshold
58
58
}
@@ -69,10 +69,10 @@ func TestDetectorNoJobs(t *testing.T) {
69
69
db , pubsub = dbtestutil .NewDB (t )
70
70
log = testutil .Logger (t )
71
71
tickCh = make (chan time.Time )
72
- statsCh = make (chan reaper .Stats )
72
+ statsCh = make (chan jobreaper .Stats )
73
73
)
74
74
75
- detector := reaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
75
+ detector := jobreaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
76
76
detector .Start ()
77
77
tickCh <- time .Now ()
78
78
@@ -92,7 +92,7 @@ func TestDetectorNoHungJobs(t *testing.T) {
92
92
db , pubsub = dbtestutil .NewDB (t )
93
93
log = testutil .Logger (t )
94
94
tickCh = make (chan time.Time )
95
- statsCh = make (chan reaper .Stats )
95
+ statsCh = make (chan jobreaper .Stats )
96
96
)
97
97
98
98
// Insert some jobs that are running and haven't been updated in a while,
@@ -119,7 +119,7 @@ func TestDetectorNoHungJobs(t *testing.T) {
119
119
})
120
120
}
121
121
122
- detector := reaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
122
+ detector := jobreaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
123
123
detector .Start ()
124
124
tickCh <- now
125
125
@@ -139,7 +139,7 @@ func TestDetectorHungWorkspaceBuild(t *testing.T) {
139
139
db , pubsub = dbtestutil .NewDB (t )
140
140
log = testutil .Logger (t )
141
141
tickCh = make (chan time.Time )
142
- statsCh = make (chan reaper .Stats )
142
+ statsCh = make (chan jobreaper .Stats )
143
143
)
144
144
145
145
var (
@@ -225,7 +225,7 @@ func TestDetectorHungWorkspaceBuild(t *testing.T) {
225
225
t .Log ("previous job ID: " , previousWorkspaceBuildJob .ID )
226
226
t .Log ("current job ID: " , currentWorkspaceBuildJob .ID )
227
227
228
- detector := reaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
228
+ detector := jobreaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
229
229
detector .Start ()
230
230
tickCh <- now
231
231
@@ -261,7 +261,7 @@ func TestDetectorHungWorkspaceBuildNoOverrideState(t *testing.T) {
261
261
db , pubsub = dbtestutil .NewDB (t )
262
262
log = testutil .Logger (t )
263
263
tickCh = make (chan time.Time )
264
- statsCh = make (chan reaper .Stats )
264
+ statsCh = make (chan jobreaper .Stats )
265
265
)
266
266
267
267
var (
@@ -348,7 +348,7 @@ func TestDetectorHungWorkspaceBuildNoOverrideState(t *testing.T) {
348
348
t .Log ("previous job ID: " , previousWorkspaceBuildJob .ID )
349
349
t .Log ("current job ID: " , currentWorkspaceBuildJob .ID )
350
350
351
- detector := reaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
351
+ detector := jobreaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
352
352
detector .Start ()
353
353
tickCh <- now
354
354
@@ -384,7 +384,7 @@ func TestDetectorHungWorkspaceBuildNoOverrideStateIfNoExistingBuild(t *testing.T
384
384
db , pubsub = dbtestutil .NewDB (t )
385
385
log = testutil .Logger (t )
386
386
tickCh = make (chan time.Time )
387
- statsCh = make (chan reaper .Stats )
387
+ statsCh = make (chan jobreaper .Stats )
388
388
)
389
389
390
390
var (
@@ -441,7 +441,7 @@ func TestDetectorHungWorkspaceBuildNoOverrideStateIfNoExistingBuild(t *testing.T
441
441
442
442
t .Log ("current job ID: " , currentWorkspaceBuildJob .ID )
443
443
444
- detector := reaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
444
+ detector := jobreaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
445
445
detector .Start ()
446
446
tickCh <- now
447
447
@@ -477,7 +477,7 @@ func TestDetectorNotStartedWorkspaceBuildNoOverrideStateIfNoExistingBuild(t *tes
477
477
db , pubsub = dbtestutil .NewDB (t )
478
478
log = testutil .Logger (t )
479
479
tickCh = make (chan time.Time )
480
- statsCh = make (chan reaper .Stats )
480
+ statsCh = make (chan jobreaper .Stats )
481
481
)
482
482
483
483
var (
@@ -533,7 +533,7 @@ func TestDetectorNotStartedWorkspaceBuildNoOverrideStateIfNoExistingBuild(t *tes
533
533
534
534
t .Log ("current job ID: " , currentWorkspaceBuildJob .ID )
535
535
536
- detector := reaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
536
+ detector := jobreaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
537
537
detector .Start ()
538
538
tickCh <- now
539
539
@@ -571,7 +571,7 @@ func TestDetectorHungOtherJobTypes(t *testing.T) {
571
571
db , pubsub = dbtestutil .NewDB (t )
572
572
log = testutil .Logger (t )
573
573
tickCh = make (chan time.Time )
574
- statsCh = make (chan reaper .Stats )
574
+ statsCh = make (chan jobreaper .Stats )
575
575
)
576
576
577
577
var (
@@ -633,7 +633,7 @@ func TestDetectorHungOtherJobTypes(t *testing.T) {
633
633
t .Log ("template import job ID: " , templateImportJob .ID )
634
634
t .Log ("template dry-run job ID: " , templateDryRunJob .ID )
635
635
636
- detector := reaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
636
+ detector := jobreaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
637
637
detector .Start ()
638
638
tickCh <- now
639
639
@@ -675,7 +675,7 @@ func TestDetectorNotStartedOtherJobTypes(t *testing.T) {
675
675
db , pubsub = dbtestutil .NewDB (t )
676
676
log = testutil .Logger (t )
677
677
tickCh = make (chan time.Time )
678
- statsCh = make (chan reaper .Stats )
678
+ statsCh = make (chan jobreaper .Stats )
679
679
)
680
680
681
681
var (
@@ -736,7 +736,7 @@ func TestDetectorNotStartedOtherJobTypes(t *testing.T) {
736
736
t .Log ("template import job ID: " , templateImportJob .ID )
737
737
t .Log ("template dry-run job ID: " , templateDryRunJob .ID )
738
738
739
- detector := reaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
739
+ detector := jobreaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
740
740
detector .Start ()
741
741
tickCh <- now
742
742
@@ -782,7 +782,7 @@ func TestDetectorHungCanceledJob(t *testing.T) {
782
782
db , pubsub = dbtestutil .NewDB (t )
783
783
log = testutil .Logger (t )
784
784
tickCh = make (chan time.Time )
785
- statsCh = make (chan reaper .Stats )
785
+ statsCh = make (chan jobreaper .Stats )
786
786
)
787
787
788
788
var (
@@ -822,7 +822,7 @@ func TestDetectorHungCanceledJob(t *testing.T) {
822
822
823
823
t .Log ("template import job ID: " , templateImportJob .ID )
824
824
825
- detector := reaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
825
+ detector := jobreaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
826
826
detector .Start ()
827
827
tickCh <- now
828
828
@@ -884,7 +884,7 @@ func TestDetectorPushesLogs(t *testing.T) {
884
884
db , pubsub = dbtestutil .NewDB (t )
885
885
log = testutil .Logger (t )
886
886
tickCh = make (chan time.Time )
887
- statsCh = make (chan reaper .Stats )
887
+ statsCh = make (chan jobreaper .Stats )
888
888
)
889
889
890
890
var (
@@ -937,7 +937,7 @@ func TestDetectorPushesLogs(t *testing.T) {
937
937
require .Len (t , logs , 10 )
938
938
}
939
939
940
- detector := reaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
940
+ detector := jobreaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
941
941
detector .Start ()
942
942
943
943
// Create pubsub subscription to listen for new log events.
@@ -1004,15 +1004,15 @@ func TestDetectorMaxJobsPerRun(t *testing.T) {
1004
1004
db , pubsub = dbtestutil .NewDB (t )
1005
1005
log = testutil .Logger (t )
1006
1006
tickCh = make (chan time.Time )
1007
- statsCh = make (chan reaper .Stats )
1007
+ statsCh = make (chan jobreaper .Stats )
1008
1008
org = dbgen .Organization (t , db , database.Organization {})
1009
1009
user = dbgen .User (t , db , database.User {})
1010
1010
file = dbgen .File (t , db , database.File {})
1011
1011
)
1012
1012
1013
1013
// Create MaxJobsPerRun + 1 hung jobs.
1014
1014
now := time .Now ()
1015
- for i := 0 ; i < reaper .MaxJobsPerRun + 1 ; i ++ {
1015
+ for i := 0 ; i < jobreaper .MaxJobsPerRun + 1 ; i ++ {
1016
1016
pj := dbgen .ProvisionerJob (t , db , pubsub , database.ProvisionerJob {
1017
1017
CreatedAt : now .Add (- time .Hour ),
1018
1018
UpdatedAt : now .Add (- time .Hour ),
@@ -1035,14 +1035,14 @@ func TestDetectorMaxJobsPerRun(t *testing.T) {
1035
1035
})
1036
1036
}
1037
1037
1038
- detector := reaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
1038
+ detector := jobreaper .New (ctx , wrapDBAuthz (db , log ), pubsub , log , tickCh ).WithStatsChannel (statsCh )
1039
1039
detector .Start ()
1040
1040
tickCh <- now
1041
1041
1042
1042
// Make sure that only MaxJobsPerRun jobs are terminated.
1043
1043
stats := <- statsCh
1044
1044
require .NoError (t , stats .Error )
1045
- require .Len (t , stats .TerminatedJobIDs , reaper .MaxJobsPerRun )
1045
+ require .Len (t , stats .TerminatedJobIDs , jobreaper .MaxJobsPerRun )
1046
1046
1047
1047
// Run the detector again and make sure that only the remaining job is
1048
1048
// terminated.
0 commit comments