Skip to content

Commit

Permalink
test: fix TestUtube_Put test
Browse files Browse the repository at this point in the history
Increased sleep duration. Added more checks.

Part of #157
  • Loading branch information
better0fdead committed Feb 7, 2023
1 parent e2142e9 commit 4a82ce9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,21 +791,29 @@ func TestUtube_Put(t *testing.T) {
close(errChan)
}()

time.Sleep(100 * time.Millisecond)
time.Sleep(500 * time.Millisecond)
// the queue should be blocked for ~2 seconds
start := time.Now()
t2, err := q.TakeTimeout(2 * time.Second)
if err != nil {
<-errChan
t.Fatalf("Failed to take task from utube: %s", err)
}

if t2 == nil {
<-errChan
t.Fatalf("Got nil task")
}

if err := t2.Ack(); err != nil {
<-errChan
t.Fatalf("Failed to ack task: %s", err)
}
end := time.Now()
if _, ok := <-errChan; ok {
t.Fatalf("One of tasks failed")
}
if math.Abs(float64(end.Sub(start)-2*time.Second)) > float64(200*time.Millisecond) {
if math.Abs(float64(end.Sub(start)-2*time.Second)) > float64(700*time.Millisecond) {
t.Fatalf("Blocking time is less than expected: actual = %.2fs, expected = 1s", end.Sub(start).Seconds())
}
}
Expand Down

0 comments on commit 4a82ce9

Please sign in to comment.