@@ -21,7 +21,7 @@ import (
21
21
"context"
22
22
"errors"
23
23
"fmt"
24
- "math/rand"
24
+ "math/rand/v2 "
25
25
"strings"
26
26
"sync"
27
27
"sync/atomic"
@@ -95,7 +95,7 @@ func TestGroup_Go(t *testing.T) {
95
95
96
96
assert .Eventually (t ,
97
97
func () bool { return want == runningCount .Load () },
98
- time .Second , 100 * time .Millisecond )
98
+ 1 * time .Second , 10 * time .Millisecond )
99
99
})
100
100
101
101
t .Run ("workloads wait for available worker" , func (t * testing.T ) {
@@ -158,7 +158,7 @@ func TestGroup_Go(t *testing.T) {
158
158
// Wait to ensure f1 and f2 are running, thus there is no workers free.
159
159
assert .Eventually (t ,
160
160
func () bool { return int64 (2 ) == runningCount .Load () },
161
- 100 * time .Millisecond , time .Millisecond )
161
+ 1 * time .Second , 10 * time .Millisecond )
162
162
163
163
err = g .Go (f3 )
164
164
require .NoError (t , err )
@@ -170,7 +170,7 @@ func TestGroup_Go(t *testing.T) {
170
170
func () bool {
171
171
return f3Started .Load ()
172
172
},
173
- 100 * time .Millisecond , time .Millisecond )
173
+ 1 * time .Second , 10 * time .Millisecond )
174
174
175
175
// If f3 started, f2 must have finished
176
176
assert .True (t , f2Finished .Load ())
@@ -186,8 +186,8 @@ func TestGroup_Go(t *testing.T) {
186
186
187
187
assert .Eventually (t ,
188
188
func () bool { return doneCount .Load () == 3 },
189
- 50 * time .Millisecond ,
190
- time .Millisecond ,
189
+ 1 * time .Second ,
190
+ 10 * time .Millisecond ,
191
191
"not all goroutines finished" )
192
192
})
193
193
@@ -202,14 +202,13 @@ func TestGroup_Go(t *testing.T) {
202
202
203
203
t .Run ("without limit, all goroutines run" , func (t * testing.T ) {
204
204
// 100 <= limit <= 10000
205
- limit := rand .Int63n (10000 - 100 ) + 100
205
+ limit := rand .IntN (10000 - 100 ) + 100
206
206
t .Logf ("running %d goroutines" , limit )
207
207
g := NewGroup (uint64 (limit ), time .Second , noopLogger {}, "" )
208
208
209
209
done := make (chan struct {})
210
210
var runningCounter atomic.Int64
211
- var i int64
212
- for i = 0 ; i < limit ; i ++ {
211
+ for i := 0 ; i < limit ; i ++ {
213
212
err := g .Go (func (context.Context ) error {
214
213
runningCounter .Add (1 )
215
214
defer runningCounter .Add (- 1 )
@@ -221,9 +220,9 @@ func TestGroup_Go(t *testing.T) {
221
220
}
222
221
223
222
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 )
227
226
228
227
close (done )
229
228
err := g .Stop ()
@@ -253,7 +252,7 @@ func TestGroup_Go(t *testing.T) {
253
252
254
253
assert .Eventually (t , func () bool {
255
254
return count .Load () == want && logger .String () != ""
256
- }, 100 * time .Millisecond , time .Millisecond )
255
+ }, 1 * time .Second , 10 * time .Millisecond )
257
256
258
257
err = g .Stop ()
259
258
require .NoError (t , err )
@@ -286,7 +285,7 @@ func TestGroup_Go(t *testing.T) {
286
285
287
286
assert .Eventually (t , func () bool {
288
287
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" )
290
289
291
290
assert .Contains (t , logger .String (), wantErr .Error ())
292
291
0 commit comments