From 0210a718f6f86a2f825d7c2aa2a225c73b4c5f6b Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 3 May 2017 10:53:35 +0200 Subject: [PATCH] fix mux test --- testing/scenarios/common.go | 12 ++++++++++++ testing/scenarios/vmess_test.go | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/testing/scenarios/common.go b/testing/scenarios/common.go index 290f467f..7044e689 100644 --- a/testing/scenarios/common.go +++ b/testing/scenarios/common.go @@ -30,6 +30,18 @@ func pickPort() v2net.Port { return v2net.Port(addr.Port) } +func pickUDPPort() v2net.Port { + conn, err := net.ListenUDP("udp4", &net.UDPAddr{ + IP: v2net.LocalHostIP.IP(), + Port: 0, + }) + common.Must(err) + defer conn.Close() + + addr := conn.LocalAddr().(*net.UDPAddr) + return v2net.Port(addr.Port) +} + func xor(b []byte) []byte { r := make([]byte, len(b)) for i, v := range b { diff --git a/testing/scenarios/vmess_test.go b/testing/scenarios/vmess_test.go index 3fa82a7a..063fe683 100644 --- a/testing/scenarios/vmess_test.go +++ b/testing/scenarios/vmess_test.go @@ -1095,7 +1095,7 @@ func TestVMessGCMMuxUDP(t *testing.T) { } clientPort := pickPort() - clientUDPPort := pickPort() + clientUDPPort := pickUDPPort() clientConfig := &core.Config{ Inbound: []*proxyman.InboundHandlerConfig{ { @@ -1203,7 +1203,7 @@ func TestVMessGCMMuxUDP(t *testing.T) { payload := make([]byte, 1024) rand.Read(payload) - for j := 0; j < 10; j++ { + for j := 0; j < 5; j++ { nBytes, _, err := conn.WriteMsgUDP(payload, nil, nil) assert.Error(err).IsNil() assert.Int(nBytes).Equals(len(payload)) @@ -1211,7 +1211,7 @@ func TestVMessGCMMuxUDP(t *testing.T) { response := make([]byte, 1024) oob := make([]byte, 16) - for j := 0; j < 10; j++ { + for j := 0; j < 5; j++ { nBytes, _, _, _, err := conn.ReadMsgUDP(response, oob) assert.Error(err).IsNil() assert.Int(nBytes).Equals(1024)