From d2103346c49cc9e20627edc9814f7a5100d38faf Mon Sep 17 00:00:00 2001 From: dudaodong Date: Sat, 7 Mar 2026 11:47:19 +0800 Subject: [PATCH] fix: fix TestRandStringConcurrent failed in github action task --- random/random_test.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/random/random_test.go b/random/random_test.go index 60d549c..54ce1cd 100644 --- a/random/random_test.go +++ b/random/random_test.go @@ -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() }