Skip to content

Commit d210334

Browse files
author
dudaodong
committed
fix: fix TestRandStringConcurrent failed in github action task
1 parent ce3967b commit d210334

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

random/random_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package random
22

33
import (
4+
"fmt"
45
"reflect"
56
"regexp"
67
"strconv"
@@ -391,17 +392,32 @@ func TestRandStringConcurrent(t *testing.T) {
391392
var wg sync.WaitGroup
392393
wg.Add(goroutines)
393394

395+
errCh := make(chan error, goroutines)
396+
394397
for g := 0; g < goroutines; g++ {
395398
go func() {
396399
defer wg.Done()
397400
for i := 0; i < iterations; i++ {
398401
s := RandString(length)
399402
if len(s) != length {
400-
t.Fatalf("unexpected string length: got %d, want %d", len(s), length)
403+
errCh <- fmt.Errorf("unexpected string length: got %d, want %d", len(s), length)
401404
}
402405
}
403406
}()
404407
}
405408

406-
wg.Wait()
409+
go func() {
410+
wg.Wait()
411+
close(errCh)
412+
}()
413+
414+
for err := range errCh {
415+
t.Errorf("test failed: %v", err)
416+
}
417+
418+
if len(errCh) > 0 {
419+
t.FailNow()
420+
}
421+
422+
// wg.Wait()
407423
}

0 commit comments

Comments
 (0)