Reorder statements for more precise behavior and harden the test (#1534)

This commit is contained in:
Victor Agababov 2020-07-21 14:14:53 -07:00 committed by GitHub
parent 0166004ef1
commit 557b6826ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -70,8 +70,8 @@ func process(q workqueue.Interface, ch chan interface{}) {
if d {
break
}
ch <- i
q.Done(i)
ch <- i
}
}

View File

@ -20,14 +20,20 @@ import (
"strconv"
"testing"
"time"
"k8s.io/apimachinery/pkg/util/wait"
)
func TestSlowQueue(t *testing.T) {
q := newTwoLaneWorkQueue("live-in-the-fast-lane")
q.SlowLane().Add("1")
if got, want := q.Len(), 1; got != want {
t.Errorf("Len = %d, want: 1", got)
// Queue has async moving parts so if we check at the wrong moment, this might still be 0.
if wait.PollImmediate(10*time.Millisecond, 250*time.Millisecond, func() (bool, error) {
return q.Len() == 1, nil
}) != nil {
t.Error("Queue length was never 1")
}
k, done := q.Get()
if got, want := k.(string), "1"; got != want {
t.Errorf(`Got = %q, want: "1"`, got)