Skip to content

Commit

Permalink
fix flaky test TestPeriodicQueueWithMultipleWorkers/queue_with_multip…
Browse files Browse the repository at this point in the history
…le_workers_should_requeue_errors

The default queue adds a 5ms delay before requeuing the item, we should
account for that before checking the number of requeueus.

Tested it works fine now:

go test -timeout 30s -run ^TestPeriodicQueueWithMultipleWorkers/queue_with_multiple_workers_should_requeue_errors$ -v k8s.io/ingress-gce/pkg/utils -c -race

stress ./utils.test -test.run ^TestPeriodicQueueWithMultipleWorkers/queue_with_multiple_workers_should_requeue_errors$
5s: 24 runs so far, 0 failures
10s: 66 runs so far, 0 failures
15s: 99 runs so far, 0 failures
20s: 133 runs so far, 0 failures
25s: 173 runs so far, 0 failures
30s: 206 runs so far, 0 failures
35s: 243 runs so far, 0 failures
40s: 284 runs so far, 0 failures

Before

20s: 143 runs so far, 5 failures (3.50%)
  • Loading branch information
aojea committed Feb 8, 2023
1 parent f3afbc6 commit c3161e5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/utils/taskqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (
"errors"
"reflect"
"testing"
"time"

"k8s.io/client-go/tools/cache"
"sync"
"time"

"k8s.io/client-go/tools/cache"
)

func TestPeriodicTaskQueue(t *testing.T) {
Expand Down Expand Up @@ -112,12 +113,13 @@ func TestPeriodicQueueWithMultipleWorkers(t *testing.T) {
for _, obj := range tc.inputObjs {
tq.Enqueue(cache.ExplicitKey(obj))
}

for tq.Len() > 0 {
time.Sleep(1 * time.Second)
}

if tc.expectRequeueForKey != "" {
// the item is requeued with a delay, by default is 5 ms in DefaultControllerRateLimiter()
time.Sleep(10 * time.Millisecond)
if tq.queue.NumRequeues(tc.expectRequeueForKey) == 0 {
t.Errorf("Got 0 requeues for %q, expected non-zero requeue on error.", tc.expectRequeueForKey)
}
Expand Down

0 comments on commit c3161e5

Please sign in to comment.