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)