Tests: Reduce RAM usage (#5577)

https://github.com/XTLS/Xray-core/pull/5577#issuecomment-3768963110
This commit is contained in:
风扇滑翔翼
2026-01-21 21:02:04 +08:00
committed by GitHub
parent e813a3744f
commit a778d3d273
+15 -2
View File
@@ -213,7 +213,8 @@ func testTCPConn2(conn net.Conn, payloadSize int, timeout time.Duration) func()
"\tSys =", units.ByteSize(m.Sys).String(),
"\tNumGC =", m.NumGC)
}()
payload := make([]byte, payloadSize)
singleWrite := func(length int) error {
payload := make([]byte, length)
common.Must2(rand.Read(payload))
nBytes, err := conn.Write(payload)
@@ -224,7 +225,7 @@ func testTCPConn2(conn net.Conn, payloadSize int, timeout time.Duration) func()
return errors.New("expect ", len(payload), " written, but actually ", nBytes)
}
response, err := readFrom2(conn, timeout, payloadSize)
response, err := readFrom2(conn, timeout, length)
if err != nil {
return err
}
@@ -236,6 +237,18 @@ func testTCPConn2(conn net.Conn, payloadSize int, timeout time.Duration) func()
return nil
}
for payloadSize > 0 {
sizeToWrite := 1024
if payloadSize < 1024 {
sizeToWrite = payloadSize
}
if err := singleWrite(sizeToWrite); err != nil {
return err
}
payloadSize -= sizeToWrite
}
return nil
}
}
func WaitConnAvailableWithTest(t *testing.T, testFunc func() error) bool {