From a778d3d273b6f07f72aa87ff980d2ca50c52542d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Wed, 21 Jan 2026 21:02:04 +0800 Subject: [PATCH] Tests: Reduce RAM usage (#5577) https://github.com/XTLS/Xray-core/pull/5577#issuecomment-3768963110 --- testing/scenarios/common.go | 47 +++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/testing/scenarios/common.go b/testing/scenarios/common.go index dc54105a..a6eea215 100644 --- a/testing/scenarios/common.go +++ b/testing/scenarios/common.go @@ -213,27 +213,40 @@ func testTCPConn2(conn net.Conn, payloadSize int, timeout time.Duration) func() "\tSys =", units.ByteSize(m.Sys).String(), "\tNumGC =", m.NumGC) }() - payload := make([]byte, payloadSize) - common.Must2(rand.Read(payload)) + singleWrite := func(length int) error { + payload := make([]byte, length) + common.Must2(rand.Read(payload)) - nBytes, err := conn.Write(payload) - if err != nil { - return err - } - if nBytes != len(payload) { - return errors.New("expect ", len(payload), " written, but actually ", nBytes) - } + nBytes, err := conn.Write(payload) + if err != nil { + return err + } + if nBytes != len(payload) { + return errors.New("expect ", len(payload), " written, but actually ", nBytes) + } - response, err := readFrom2(conn, timeout, payloadSize) - if err != nil { - return err - } - _ = response + response, err := readFrom2(conn, timeout, length) + if err != nil { + return err + } + _ = response - if r := bytes.Compare(response, xor(payload)); r != 0 { - return errors.New(r) - } + if r := bytes.Compare(response, xor(payload)); r != 0 { + return errors.New(r) + } + return nil + } + for payloadSize > 0 { + sizeToWrite := 1024 + if payloadSize < 1024 { + sizeToWrite = payloadSize + } + if err := singleWrite(sizeToWrite); err != nil { + return err + } + payloadSize -= sizeToWrite + } return nil } }