@@ -19,9 +19,13 @@ func TestAllocEndpoint_List(t *testing.T) {
19
19
20
20
// Create the register request
21
21
alloc := mock .Alloc ()
22
+ summary := mock .JobSummary (alloc .JobID )
22
23
state := s1 .fsm .State ()
23
- err := state .UpsertAllocs (1000 , []* structs.Allocation {alloc })
24
- if err != nil {
24
+
25
+ if err := state .UpsertJobSummary (999 , summary ); err != nil {
26
+ t .Fatalf ("err: %v" , err )
27
+ }
28
+ if err := state .UpsertAllocs (1000 , []* structs.Allocation {alloc }); err != nil {
25
29
t .Fatalf ("err: %v" , err )
26
30
}
27
31
@@ -75,6 +79,10 @@ func TestAllocEndpoint_List_Blocking(t *testing.T) {
75
79
// Create the alloc
76
80
alloc := mock .Alloc ()
77
81
82
+ summary := mock .JobSummary (alloc .JobID )
83
+ if err := state .UpsertJobSummary (1 , summary ); err != nil {
84
+ t .Fatalf ("err: %v" , err )
85
+ }
78
86
// Upsert alloc triggers watches
79
87
time .AfterFunc (100 * time .Millisecond , func () {
80
88
if err := state .UpsertAllocs (2 , []* structs.Allocation {alloc }); err != nil {
@@ -109,12 +117,13 @@ func TestAllocEndpoint_List_Blocking(t *testing.T) {
109
117
alloc2 .ID = alloc .ID
110
118
alloc2 .ClientStatus = structs .AllocClientStatusRunning
111
119
time .AfterFunc (100 * time .Millisecond , func () {
112
- if err := state .UpdateAllocsFromClient (3 , []* structs.Allocation {alloc2 }); err != nil {
120
+ state .UpsertJobSummary (3 , mock .JobSummary (alloc2 .JobID ))
121
+ if err := state .UpdateAllocsFromClient (4 , []* structs.Allocation {alloc2 }); err != nil {
113
122
t .Fatalf ("err: %v" , err )
114
123
}
115
124
})
116
125
117
- req .MinQueryIndex = 2
126
+ req .MinQueryIndex = 3
118
127
start = time .Now ()
119
128
var resp2 structs.AllocListResponse
120
129
if err := msgpackrpc .CallWithCodec (codec , "Alloc.List" , req , & resp2 ); err != nil {
@@ -124,8 +133,8 @@ func TestAllocEndpoint_List_Blocking(t *testing.T) {
124
133
if elapsed := time .Since (start ); elapsed < 100 * time .Millisecond {
125
134
t .Fatalf ("should block (returned in %s) %#v" , elapsed , resp2 )
126
135
}
127
- if resp2 .Index != 3 {
128
- t .Fatalf ("Bad index: %d %d" , resp2 .Index , 3 )
136
+ if resp2 .Index != 4 {
137
+ t .Fatalf ("Bad index: %d %d" , resp2 .Index , 4 )
129
138
}
130
139
if len (resp2 .Allocations ) != 1 || resp .Allocations [0 ].ID != alloc .ID ||
131
140
resp2 .Allocations [0 ].ClientStatus != structs .AllocClientStatusRunning {
@@ -142,6 +151,7 @@ func TestAllocEndpoint_GetAlloc(t *testing.T) {
142
151
// Create the register request
143
152
alloc := mock .Alloc ()
144
153
state := s1 .fsm .State ()
154
+ state .UpsertJobSummary (999 , mock .JobSummary (alloc .JobID ))
145
155
err := state .UpsertAllocs (1000 , []* structs.Allocation {alloc })
146
156
if err != nil {
147
157
t .Fatalf ("err: %v" , err )
@@ -178,6 +188,7 @@ func TestAllocEndpoint_GetAlloc_Blocking(t *testing.T) {
178
188
179
189
// First create an unrelated alloc
180
190
time .AfterFunc (100 * time .Millisecond , func () {
191
+ state .UpsertJobSummary (99 , mock .JobSummary (alloc1 .JobID ))
181
192
err := state .UpsertAllocs (100 , []* structs.Allocation {alloc1 })
182
193
if err != nil {
183
194
t .Fatalf ("err: %v" , err )
@@ -186,6 +197,7 @@ func TestAllocEndpoint_GetAlloc_Blocking(t *testing.T) {
186
197
187
198
// Create the alloc we are watching later
188
199
time .AfterFunc (200 * time .Millisecond , func () {
200
+ state .UpsertJobSummary (999 , mock .JobSummary (alloc2 .JobID ))
189
201
err := state .UpsertAllocs (200 , []* structs.Allocation {alloc2 })
190
202
if err != nil {
191
203
t .Fatalf ("err: %v" , err )
@@ -227,6 +239,8 @@ func TestAllocEndpoint_GetAllocs(t *testing.T) {
227
239
alloc := mock .Alloc ()
228
240
alloc2 := mock .Alloc ()
229
241
state := s1 .fsm .State ()
242
+ state .UpsertJobSummary (998 , mock .JobSummary (alloc .JobID ))
243
+ state .UpsertJobSummary (999 , mock .JobSummary (alloc2 .JobID ))
230
244
err := state .UpsertAllocs (1000 , []* structs.Allocation {alloc , alloc2 })
231
245
if err != nil {
232
246
t .Fatalf ("err: %v" , err )
0 commit comments