Skip to content

Commit 7436f5f

Browse files
mergify[bot]rdner
andauthored
Give TestCloseChannel more time to close the channel (#4422) (#4428)
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. (cherry picked from commit 775e020) Co-authored-by: Denis <denis.rechkunov@elastic.co>
1 parent 139f72e commit 7436f5f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

internal/pkg/core/backoff/backoff_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
type factory func(<-chan struct{}) Backoff
1616

1717
func TestCloseChannel(t *testing.T) {
18-
init := 2 * time.Millisecond
18+
init := time.Second
1919
max := 5 * time.Second
2020

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

6060
startedAt := time.Now()
6161
assert.True(t, WaitOnError(b, errors.New("bad bad")))
62-
assert.True(t, time.Now().Sub(startedAt) >= init)
62+
assert.True(t, time.Since(startedAt) >= init)
6363
})
6464
}
6565
}
@@ -87,7 +87,7 @@ func TestNextWait(t *testing.T) {
8787

8888
startedAt := time.Now()
8989
b.Wait()
90-
waitDuration := time.Now().Sub(startedAt)
90+
waitDuration := time.Since(startedAt)
9191
nextWait := b.NextWait()
9292

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

0 commit comments

Comments
 (0)