Skip to content

Commit 5956d32

Browse files
fix(tests): relax TestGroup_Go timeouts (#42862) (#42909)
(cherry picked from commit a4bc9f0) Co-authored-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
1 parent a33e883 commit 5956d32

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

Diff for: filebeat/input/filestream/internal/task/group_test.go

+13-14
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"context"
2222
"errors"
2323
"fmt"
24-
"math/rand"
24+
"math/rand/v2"
2525
"strings"
2626
"sync"
2727
"sync/atomic"
@@ -95,7 +95,7 @@ func TestGroup_Go(t *testing.T) {
9595

9696
assert.Eventually(t,
9797
func() bool { return want == runningCount.Load() },
98-
time.Second, 100*time.Millisecond)
98+
1*time.Second, 10*time.Millisecond)
9999
})
100100

101101
t.Run("workloads wait for available worker", func(t *testing.T) {
@@ -158,7 +158,7 @@ func TestGroup_Go(t *testing.T) {
158158
// Wait to ensure f1 and f2 are running, thus there is no workers free.
159159
assert.Eventually(t,
160160
func() bool { return int64(2) == runningCount.Load() },
161-
100*time.Millisecond, time.Millisecond)
161+
1*time.Second, 10*time.Millisecond)
162162

163163
err = g.Go(f3)
164164
require.NoError(t, err)
@@ -170,7 +170,7 @@ func TestGroup_Go(t *testing.T) {
170170
func() bool {
171171
return f3Started.Load()
172172
},
173-
100*time.Millisecond, time.Millisecond)
173+
1*time.Second, 10*time.Millisecond)
174174

175175
// If f3 started, f2 must have finished
176176
assert.True(t, f2Finished.Load())
@@ -186,8 +186,8 @@ func TestGroup_Go(t *testing.T) {
186186

187187
assert.Eventually(t,
188188
func() bool { return doneCount.Load() == 3 },
189-
50*time.Millisecond,
190-
time.Millisecond,
189+
1*time.Second,
190+
10*time.Millisecond,
191191
"not all goroutines finished")
192192
})
193193

@@ -202,14 +202,13 @@ func TestGroup_Go(t *testing.T) {
202202

203203
t.Run("without limit, all goroutines run", func(t *testing.T) {
204204
// 100 <= limit <= 10000
205-
limit := rand.Int63n(10000-100) + 100
205+
limit := rand.IntN(10000-100) + 100
206206
t.Logf("running %d goroutines", limit)
207207
g := NewGroup(uint64(limit), time.Second, noopLogger{}, "")
208208

209209
done := make(chan struct{})
210210
var runningCounter atomic.Int64
211-
var i int64
212-
for i = 0; i < limit; i++ {
211+
for i := 0; i < limit; i++ {
213212
err := g.Go(func(context.Context) error {
214213
runningCounter.Add(1)
215214
defer runningCounter.Add(-1)
@@ -221,9 +220,9 @@ func TestGroup_Go(t *testing.T) {
221220
}
222221

223222
assert.Eventually(t,
224-
func() bool { return limit == runningCounter.Load() },
225-
100*time.Millisecond,
226-
time.Millisecond)
223+
func() bool { return int64(limit) == runningCounter.Load() },
224+
1*time.Second,
225+
10*time.Millisecond)
227226

228227
close(done)
229228
err := g.Stop()
@@ -253,7 +252,7 @@ func TestGroup_Go(t *testing.T) {
253252

254253
assert.Eventually(t, func() bool {
255254
return count.Load() == want && logger.String() != ""
256-
}, 100*time.Millisecond, time.Millisecond)
255+
}, 1*time.Second, 10*time.Millisecond)
257256

258257
err = g.Stop()
259258
require.NoError(t, err)
@@ -286,7 +285,7 @@ func TestGroup_Go(t *testing.T) {
286285

287286
assert.Eventually(t, func() bool {
288287
return count.Load() == want && logger.String() != ""
289-
}, 100*time.Millisecond, time.Millisecond, "not all workloads finished")
288+
}, 1*time.Second, 10*time.Millisecond, "not all workloads finished")
290289

291290
assert.Contains(t, logger.String(), wantErr.Error())
292291

0 commit comments

Comments
 (0)