Skip to content

Commit bd24bb3

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

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
@@ -185,24 +185,15 @@ var _ = Describe("Controllerworkqueue", func() {
185185
})
186186

187187
It("returns high priority item that became ready before low priority item", func() {
188-
q, metrics := newQueue()
188+
q, metrics, forwardQueueTimeBy := newQueueWithTimeForwarder()
189189
defer q.ShutDown()
190190

191-
now := time.Now().Round(time.Second)
192-
nowLock := sync.Mutex{}
193-
tick := make(chan time.Time)
194191
tickSetup := make(chan any)
195-
196-
cwq := q.(*priorityqueue[string])
197-
cwq.now = func() time.Time {
198-
nowLock.Lock()
199-
defer nowLock.Unlock()
200-
return now
201-
}
202-
cwq.tick = func(d time.Duration) <-chan time.Time {
192+
originalTick := q.tick
193+
q.tick = func(d time.Duration) <-chan time.Time {
203194
Expect(d).To(Equal(time.Second))
204195
close(tickSetup)
205-
return tick
196+
return originalTick(d)
206197
}
207198

208199
lowPriority := -100
@@ -212,11 +203,7 @@ var _ = Describe("Controllerworkqueue", func() {
212203

213204
Eventually(tickSetup).Should(BeClosed())
214205

215-
nowLock.Lock()
216-
now = now.Add(time.Second)
217-
nowLock.Unlock()
218-
tick <- now
219-
206+
forwardQueueTimeBy(1 * time.Second)
220207
key, prio, _ := q.GetWithPriority()
221208

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

0 commit comments

Comments
 (0)