From 3aa972e2fc4bd324e61903072efac19458be4c74 Mon Sep 17 00:00:00 2001 From: newacorn Date: Sat, 31 Aug 2024 20:27:05 +0800 Subject: [PATCH] Fix issues with tests interfering with each other in certain situations. (#1842) In some cases, the goroutines started by one test do not terminate smoothly before the next round of tests begins, causing interference between tests. Performance Impact: This results in test completion times not increasing linearly with the count value. Correctness Impact: It affects the accuracy of memory allocation test cases. --- client_test.go | 1 + server_test.go | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/client_test.go b/client_test.go index 844f989..40ad13a 100644 --- a/client_test.go +++ b/client_test.go @@ -1432,6 +1432,7 @@ func TestHostClientMaxConnsWithDeadline(t *testing.T) { continue } t.Errorf("unexpected error: %v", err) + return } break } diff --git a/server_test.go b/server_test.go index 3fd0b0b..75ea137 100644 --- a/server_test.go +++ b/server_test.go @@ -4141,7 +4141,10 @@ func TestMaxReadTimeoutPerRequest(t *testing.T) { // write body for i := 0; i < 5*1024; i++ { time.Sleep(time.Millisecond) - cc.Write([]byte{'a'}) //nolint:errcheck + _, err = cc.Write([]byte{'a'}) + if err != nil { + return + } } }() ch := make(chan error) @@ -4168,7 +4171,10 @@ func TestMaxWriteTimeoutPerRequest(t *testing.T) { ctx.SetBodyStreamWriter(func(w *bufio.Writer) { var buf [192]byte for { - w.Write(buf[:]) //nolint:errcheck + _, err := w.Write(buf[:]) + if err != nil { + return + } } }) }, @@ -4201,7 +4207,10 @@ func TestMaxWriteTimeoutPerRequest(t *testing.T) { var chunk [192]byte for { time.Sleep(time.Millisecond) - br.Read(chunk[:]) //nolint:errcheck + _, err = br.Read(chunk[:]) + if err != nil { + return + } } }() ch := make(chan error)