mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-05-14 10:00:34 +00:00
Tests: Reduce RAM usage (#5577)
https://github.com/XTLS/Xray-core/pull/5577#issuecomment-3768963110
This commit is contained in:
+30
-17
@@ -213,27 +213,40 @@ func testTCPConn2(conn net.Conn, payloadSize int, timeout time.Duration) func()
|
|||||||
"\tSys =", units.ByteSize(m.Sys).String(),
|
"\tSys =", units.ByteSize(m.Sys).String(),
|
||||||
"\tNumGC =", m.NumGC)
|
"\tNumGC =", m.NumGC)
|
||||||
}()
|
}()
|
||||||
payload := make([]byte, payloadSize)
|
singleWrite := func(length int) error {
|
||||||
common.Must2(rand.Read(payload))
|
payload := make([]byte, length)
|
||||||
|
common.Must2(rand.Read(payload))
|
||||||
|
|
||||||
nBytes, err := conn.Write(payload)
|
nBytes, err := conn.Write(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if nBytes != len(payload) {
|
if nBytes != len(payload) {
|
||||||
return errors.New("expect ", len(payload), " written, but actually ", nBytes)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_ = response
|
_ = response
|
||||||
|
|
||||||
if r := bytes.Compare(response, xor(payload)); r != 0 {
|
if r := bytes.Compare(response, xor(payload)); r != 0 {
|
||||||
return errors.New(r)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user