@@ -197,13 +197,14 @@ var _ = Describe("Controllerworkqueue", func() {
197
197
Expect (metrics .retries ["test" ]).To (Equal (1 ))
198
198
})
199
199
200
- It ("returns high priority item that became ready before low priority items " , func () {
200
+ It ("returns high priority item that became ready before low priority item " , func () {
201
201
q , metrics := newQueue ()
202
202
defer q .ShutDown ()
203
203
204
204
now := time .Now ().Round (time .Second )
205
205
nowLock := sync.Mutex {}
206
206
tick := make (chan time.Time )
207
+ tickSetup := make (chan any )
207
208
208
209
cwq := q .(* priorityqueue [string ])
209
210
cwq .now = func () time.Time {
@@ -213,47 +214,28 @@ var _ = Describe("Controllerworkqueue", func() {
213
214
}
214
215
cwq .tick = func (d time.Duration ) <- chan time.Time {
215
216
Expect (d ).To (Equal (time .Second ))
217
+ close (tickSetup )
216
218
return tick
217
219
}
218
220
219
- retrievedItem := make (chan any )
220
- getNext := make (chan any )
221
-
222
- go func () {
223
- defer GinkgoRecover ()
224
- defer close (retrievedItem )
225
-
226
- key , prio , _ := q .GetWithPriority ()
227
- Expect (key ).To (Equal ("foo" ))
228
- Expect (prio ).To (Equal (- 100 ))
229
-
230
- retrievedItem <- nil
231
- <- getNext
232
-
233
- key , prio , _ = q .GetWithPriority ()
234
- Expect (key ).To (Equal ("prio" ))
235
- Expect (prio ).To (Equal (0 ))
236
- }()
237
-
238
221
lowPriority := - 100
239
222
highPriority := 0
240
223
q .AddWithOpts (AddOpts {After : 0 , Priority : & lowPriority }, "foo" )
241
- q .AddWithOpts (AddOpts {After : 0 , Priority : & lowPriority }, "bar" )
242
224
q .AddWithOpts (AddOpts {After : time .Second , Priority : & highPriority }, "prio" )
243
225
244
- <- retrievedItem
226
+ Eventually ( tickSetup ). Should ( BeClosed ())
245
227
246
228
nowLock .Lock ()
247
229
now = now .Add (time .Second )
248
230
nowLock .Unlock ()
249
231
tick <- now
250
- getNext <- nil
251
232
252
- Eventually (retrievedItem ).Should (BeClosed ())
253
- close (getNext )
233
+ key , prio , _ := q .GetWithPriority ()
254
234
235
+ Expect (key ).To (Equal ("prio" ))
236
+ Expect (prio ).To (Equal (0 ))
255
237
Expect (metrics .depth ["test" ]).To (Equal (map [int ]int {- 100 : 1 , 0 : 0 }))
256
- Expect (metrics .adds ["test" ]).To (Equal (3 ))
238
+ Expect (metrics .adds ["test" ]).To (Equal (2 ))
257
239
Expect (metrics .retries ["test" ]).To (Equal (1 ))
258
240
})
259
241
0 commit comments