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