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

Function TestCopyShifting

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

Source from the content-addressed store, hash-verified

178}
179
180func TestCopyShifting(t *testing.T) {
181 fakeClock := clock.NewFakeClock(time.Now())
182 q := newDelayingQueue(fakeClock, "")
183
184 first := "foo"
185 second := "bar"
186 third := "baz"
187
188 q.AddAfter(first, 1*time.Second)
189 q.AddAfter(second, 500*time.Millisecond)
190 q.AddAfter(third, 250*time.Millisecond)
191 if err := waitForWaitingQueueToFill(q); err != nil {
192 t.Fatalf("unexpected err: %v", err)
193 }
194
195 if q.Len() != 0 {
196 t.Errorf("should not have added")
197 }
198
199 fakeClock.Step(2 * time.Second)
200
201 if err := waitForAdded(q, 3); err != nil {
202 t.Fatalf("unexpected err: %v", err)
203 }
204 actualFirst, _ := q.Get()
205 if !reflect.DeepEqual(actualFirst, third) {
206 t.Errorf("expected %v, got %v", third, actualFirst)
207 }
208 actualSecond, _ := q.Get()
209 if !reflect.DeepEqual(actualSecond, second) {
210 t.Errorf("expected %v, got %v", second, actualSecond)
211 }
212 actualThird, _ := q.Get()
213 if !reflect.DeepEqual(actualThird, first) {
214 t.Errorf("expected %v, got %v", first, actualThird)
215 }
216}
217
218func BenchmarkDelayingQueue_AddAfter(b *testing.B) {
219 r := rand.New(rand.NewSource(time.Now().Unix()))

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected