MCPcopy
hub / github.com/kubernetes/client-go / TestSimpleQueue

Function TestSimpleQueue

util/workqueue/delaying_queue_test.go:30–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestSimpleQueue(t *testing.T) {
31 fakeClock := clock.NewFakeClock(time.Now())
32 q := newDelayingQueue(fakeClock, "")
33
34 first := "foo"
35
36 q.AddAfter(first, 50*time.Millisecond)
37 if err := waitForWaitingQueueToFill(q); err != nil {
38 t.Fatalf("unexpected err: %v", err)
39 }
40
41 if q.Len() != 0 {
42 t.Errorf("should not have added")
43 }
44
45 fakeClock.Step(60 * time.Millisecond)
46
47 if err := waitForAdded(q, 1); err != nil {
48 t.Errorf("should have added")
49 }
50 item, _ := q.Get()
51 q.Done(item)
52
53 // step past the next heartbeat
54 fakeClock.Step(10 * time.Second)
55
56 err := wait.Poll(1*time.Millisecond, 30*time.Millisecond, func() (done bool, err error) {
57 if q.Len() > 0 {
58 return false, fmt.Errorf("added to queue")
59 }
60
61 return false, nil
62 })
63 if err != wait.ErrWaitTimeout {
64 t.Errorf("expected timeout, got: %v", err)
65 }
66
67 if q.Len() != 0 {
68 t.Errorf("should not have added")
69 }
70}
71
72func TestDeduping(t *testing.T) {
73 fakeClock := clock.NewFakeClock(time.Now())

Callers

nothing calls this directly

Calls 9

newDelayingQueueFunction · 0.85
waitForAddedFunction · 0.85
NowMethod · 0.65
AddAfterMethod · 0.65
LenMethod · 0.65
ErrorfMethod · 0.65
GetMethod · 0.65
DoneMethod · 0.65

Tested by

no test coverage detected