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.
This commit is contained in:
newacorn
2024-08-31 20:27:05 +08:00
committed by GitHub
parent f789432e77
commit 3aa972e2fc
2 changed files with 13 additions and 3 deletions
+1
View File
@@ -1432,6 +1432,7 @@ func TestHostClientMaxConnsWithDeadline(t *testing.T) {
continue
}
t.Errorf("unexpected error: %v", err)
return
}
break
}
+12 -3
View File
@@ -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)