Skip to content

Commit

Permalink
Fix LiveGenerator test
Browse files Browse the repository at this point in the history
  • Loading branch information
v-byte-cpu committed Mar 22, 2021
1 parent 99c3177 commit 2c8f288
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions pkg/scan/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,27 +223,22 @@ func TestScanRequests(t *testing.T) {

func TestLiveRequestGeneratorContextExit(t *testing.T) {
t.Parallel()

rg := NewLiveRequestGenerator(5 * time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond)
defer cancel()
ctx, cancel := context.WithCancel(context.Background())
cancel()
requests, err := rg.GenerateRequests(ctx, newScanRange())
require.NoError(t, err)
capacity := cap(requests)
cnt := 0
time.Sleep(1 * time.Microsecond)
// consume all requests
loop:
for {
select {
case _, ok := <-requests:
if !ok {
break loop
}
if cnt > capacity {
require.FailNow(t, "number of elements more than channel capacity")
}
cnt++
case <-time.After(waitTimeout):
require.FailNow(t, "wait timeout")
require.Fail(t, "test timeout")
}
}
}

0 comments on commit 2c8f288

Please sign in to comment.