mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix: fix TestRandStringConcurrent failed in github action task
This commit is contained in:
1 parent
ce3967b1d5
commit
d2103346c4
1 file changed
+18
-2
+18
-2
@@ -1,6 +1,7 @@
|
|||||||
package random
|
package random
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -391,17 +392,32 @@ func TestRandStringConcurrent(t *testing.T) {
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(goroutines)
|
wg.Add(goroutines)
|
||||||
|
|
||||||
|
errCh := make(chan error, goroutines)
|
||||||
|
|
||||||
for g := 0; g < goroutines; g++ {
|
for g := 0; g < goroutines; g++ {
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for i := 0; i < iterations; i++ {
|
for i := 0; i < iterations; i++ {
|
||||||
s := RandString(length)
|
s := RandString(length)
|
||||||
if len(s) != 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