Skip to content

Commit 5f2c4ea

Browse files
moritzmoekstiehl
authored andcommitted
fix test
Co-authored-by: kstiehl <[email protected]>
1 parent a22adbe commit 5f2c4ea

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

pkg/controller/priorityqueue/priorityqueue_test.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,24 +198,15 @@ var _ = Describe("Controllerworkqueue", func() {
198198
})
199199

200200
It("returns high priority item that became ready before low priority item", func() {
201-
q, metrics := newQueue()
201+
q, metrics, forwardQueueTimeBy := newQueueWithTimeForwarder()
202202
defer q.ShutDown()
203203

204-
now := time.Now().Round(time.Second)
205-
nowLock := sync.Mutex{}
206-
tick := make(chan time.Time)
207204
tickSetup := make(chan any)
208-
209-
cwq := q.(*priorityqueue[string])
210-
cwq.now = func() time.Time {
211-
nowLock.Lock()
212-
defer nowLock.Unlock()
213-
return now
214-
}
215-
cwq.tick = func(d time.Duration) <-chan time.Time {
205+
originalTick := q.tick
206+
q.tick = func(d time.Duration) <-chan time.Time {
216207
Expect(d).To(Equal(time.Second))
217208
close(tickSetup)
218-
return tick
209+
return originalTick(d)
219210
}
220211

221212
lowPriority := -100
@@ -225,11 +216,7 @@ var _ = Describe("Controllerworkqueue", func() {
225216

226217
Eventually(tickSetup).Should(BeClosed())
227218

228-
nowLock.Lock()
229-
now = now.Add(time.Second)
230-
nowLock.Unlock()
231-
tick <- now
232-
219+
forwardQueueTimeBy(1 * time.Second)
233220
key, prio, _ := q.GetWithPriority()
234221

235222
Expect(key).To(Equal("prio"))

0 commit comments

Comments
 (0)