Skip to content

Commit

Permalink
Give TestCloseChannel more time to close the channel (#4422)
Browse files Browse the repository at this point in the history
If the initial wait is short it's possible that `time.After` unblocks
faster than the channel gets closed. Which makes this test to fail.
  • Loading branch information
rdner authored Mar 18, 2024
1 parent 8e6593f commit 775e020
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/pkg/core/backoff/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type factory func(<-chan struct{}) Backoff

func TestCloseChannel(t *testing.T) {
init := 2 * time.Millisecond
init := time.Second
max := 5 * time.Second

tests := map[string]factory{
Expand All @@ -32,7 +32,7 @@ func TestCloseChannel(t *testing.T) {
c := make(chan struct{})
b := f(c)
close(c)
assert.False(t, b.Wait())
assert.False(t, b.Wait(), "should return false because the channel shuld get closed faster than the next wait duration")
})
}
}
Expand All @@ -59,7 +59,7 @@ func TestUnblockAfterInit(t *testing.T) {

startedAt := time.Now()
assert.True(t, WaitOnError(b, errors.New("bad bad")))
assert.True(t, time.Now().Sub(startedAt) >= init)
assert.True(t, time.Since(startedAt) >= init)
})
}
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestNextWait(t *testing.T) {

startedAt := time.Now()
b.Wait()
waitDuration := time.Now().Sub(startedAt)
waitDuration := time.Since(startedAt)
nextWait := b.NextWait()

t.Logf("actualWait: %s startWait: %s nextWait: %s", waitDuration, startWait, nextWait)
Expand Down

0 comments on commit 775e020

Please sign in to comment.