@@ -25,6 +25,7 @@ func TestAllocReconciler_PropTest(t *testing.T) {
25
25
t .Run ("batch jobs" , rapid .MakeCheck (func (t * rapid.T ) {
26
26
ar := genAllocReconciler (structs .JobTypeBatch , & idGenerator {}).Draw (t , "reconciler" )
27
27
results := ar .Compute ()
28
+
28
29
if results == nil {
29
30
t .Fatal ("results should never be nil" )
30
31
}
@@ -34,10 +35,48 @@ func TestAllocReconciler_PropTest(t *testing.T) {
34
35
t .Run ("service jobs" , rapid .MakeCheck (func (t * rapid.T ) {
35
36
ar := genAllocReconciler (structs .JobTypeService , & idGenerator {}).Draw (t , "reconciler" )
36
37
results := ar .Compute ()
38
+
39
+ /*
40
+ SAFETY properties ("something bad never happens")
41
+ */
42
+
37
43
if results == nil {
38
44
t .Fatal ("results should never be nil" )
39
45
}
40
- // TODO(tgross): this where the properties under test go
46
+
47
+ // stopped jobs
48
+ if ar .jobState .Job .Stopped () {
49
+ if ar .jobState .DeploymentCurrent != nil {
50
+ if results .Deployment != nil {
51
+ t .Fatal ("stopped jobs with current deployments should never result in a new deployment" )
52
+ }
53
+ if results .Stop == nil {
54
+ t .Fatal ("stopped jobs with current deployments should always have stopped allocs" )
55
+ }
56
+ }
57
+ }
58
+
59
+ if results .DesiredTGUpdates == nil {
60
+ t .Fatal ("we should never have nil desired task group updates" )
61
+ }
62
+
63
+ if ar .jobState .DeploymentFailed && results .Deployment != nil {
64
+ t .Fatal ("failed deployments should never result in new deployments" )
65
+ }
66
+
67
+ if ! ar .clusterState .SupportsDisconnectedClients && results .ReconnectUpdates != nil {
68
+ t .Fatal ("task groups that don't support disconnected clients should never result in reconnect updates" )
69
+ }
70
+
71
+ if ar .jobState .DeploymentCurrent == nil && ar .jobState .DeploymentOld == nil && len (ar .jobState .ExistingAllocs ) == 0 {
72
+ count := 0
73
+ for _ , tg := range ar .jobState .Job .TaskGroups {
74
+ count += tg .Count
75
+ }
76
+ if len (results .Place ) > count {
77
+ t .Fatal ("for new jobs, amount of allocs to place should never exceed total tg count" )
78
+ }
79
+ }
41
80
}))
42
81
}
43
82
@@ -125,7 +164,7 @@ func genDeployment(idg *idGenerator, job *structs.Job, allocs []*structs.Allocat
125
164
AutoPromote : tg .Update .AutoPromote ,
126
165
ProgressDeadline : tg .Update .ProgressDeadline ,
127
166
RequireProgressBy : time.Time {},
128
- Promoted : false , // TODO(tgross): what to do with this?
167
+ Promoted : rapid . Bool (). Draw ( t , "promoted" ),
129
168
PlacedCanaries : []string {},
130
169
DesiredCanaries : tg .Update .Canary ,
131
170
DesiredTotal : tg .Count ,
@@ -163,13 +202,20 @@ func genDeployment(idg *idGenerator, job *structs.Job, allocs []*structs.Allocat
163
202
JobCreateIndex : job .CreateIndex ,
164
203
IsMultiregion : false ,
165
204
TaskGroups : dstates ,
166
- Status : structs .DeploymentStatusRunning , // TODO(tgross)
167
- StatusDescription : "" ,
168
- EvalPriority : 0 ,
169
- CreateIndex : job .CreateIndex ,
170
- ModifyIndex : 0 ,
171
- CreateTime : 0 ,
172
- ModifyTime : 0 ,
205
+ Status : rapid .SampledFrom ([]string {
206
+ structs .DeploymentStatusRunning ,
207
+ structs .DeploymentStatusPending ,
208
+ structs .DeploymentStatusInitializing ,
209
+ structs .DeploymentStatusPaused ,
210
+ structs .DeploymentStatusFailed ,
211
+ structs .DeploymentStatusSuccessful ,
212
+ }).Draw (t , "deployment_status" ),
213
+ StatusDescription : "" ,
214
+ EvalPriority : 0 ,
215
+ CreateIndex : job .CreateIndex ,
216
+ ModifyIndex : 0 ,
217
+ CreateTime : 0 ,
218
+ ModifyTime : 0 ,
173
219
}
174
220
})
175
221
}
0 commit comments