mirror of
https://github.com/duke-git/lancet.git
synced 2026-04-22 16:07:21 +08:00
fix: fix TestRandStringConcurrent failed in github action task
This commit is contained in:
+18
-2
@@ -1,6 +1,7 @@
|
||||
package random
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -391,17 +392,32 @@ func TestRandStringConcurrent(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(goroutines)
|
||||
|
||||
errCh := make(chan error, goroutines)
|
||||
|
||||
for g := 0; g < goroutines; g++ {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for i := 0; i < iterations; i++ {
|
||||
s := RandString(length)
|
||||
if len(s) != length {
|
||||
t.Fatalf("unexpected string length: got %d, want %d", len(s), length)
|
||||
errCh <- fmt.Errorf("unexpected string length: got %d, want %d", len(s), length)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
go func() {
|
||||
wg.Wait()
|
||||
close(errCh)
|
||||
}()
|
||||
|
||||
for err := range errCh {
|
||||
t.Errorf("test failed: %v", err)
|
||||
}
|
||||
|
||||
if len(errCh) > 0 {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
// wg.Wait()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user