From b5e3b5bb8345834c679cf814734d99a67c516ddc 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: Thu, 14 Aug 2025 10:04:09 +0000 Subject: [PATCH] Refactor Test_maxUpload logic --- .../internet/splithttp/splithttp_test.go | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/transport/internet/splithttp/splithttp_test.go b/transport/internet/splithttp/splithttp_test.go index 1db54255..c1bb8580 100644 --- a/transport/internet/splithttp/splithttp_test.go +++ b/transport/internet/splithttp/splithttp_test.go @@ -1,6 +1,7 @@ package splithttp_test import ( + "bytes" "context" "crypto/rand" "fmt" @@ -421,18 +422,12 @@ func Test_maxUpload(t *testing.T) { }, } - var uploadSize int + uploadReceived := make([]byte, 10001) listen, err := ListenXH(context.Background(), net.LocalHostIP, listenPort, streamSettings, func(conn stat.Connection) { go func(c stat.Connection) { defer c.Close() - var b [10240]byte c.SetReadDeadline(time.Now().Add(2 * time.Second)) - n, err := c.Read(b[:]) - if err != nil { - return - } - - uploadSize = n + io.ReadFull(c, uploadReceived) common.Must2(c.Write([]byte("Response"))) }(conn) @@ -441,10 +436,12 @@ func Test_maxUpload(t *testing.T) { ctx := context.Background() conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), listenPort), streamSettings) + common.Must(err) // send a slightly too large upload - var upload [10001]byte - _, err = conn.Write(upload[:]) + upload := make([]byte, 10001) + rand.Read(upload) + _, err = conn.Write(upload) common.Must(err) var b [10240]byte @@ -455,8 +452,8 @@ func Test_maxUpload(t *testing.T) { } common.Must(conn.Close()) - if uploadSize > 10000 || uploadSize == 0 { - t.Error("incorrect upload size: ", uploadSize) + if !bytes.Equal(upload, uploadReceived) { + t.Error("incorrect upload", upload, uploadReceived) } common.Must(listen.Close())