Test: fix direct listen fail
This commit is contained in:
parent
fda82d1748
commit
f74b7468c7
3 changed files with 45 additions and 6 deletions
|
@ -210,7 +210,7 @@ func newLargeDataPair() (chan hashPair, chan hashPair, func(t *testing.T) error)
|
|||
func testPingPongWithSocksPort(t *testing.T, port int) {
|
||||
pingCh, pongCh, test := newPingPongPair()
|
||||
go func() {
|
||||
l, err := net.Listen("tcp", ":10001")
|
||||
l, err := Listen("tcp", ":10001")
|
||||
if err != nil {
|
||||
assert.FailNow(t, err.Error())
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ func testPingPongWithSocksPort(t *testing.T, port int) {
|
|||
}
|
||||
|
||||
func testPingPongWithConn(t *testing.T, c net.Conn) error {
|
||||
l, err := net.Listen("tcp", ":10001")
|
||||
l, err := Listen("tcp", ":10001")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ func testPingPongWithConn(t *testing.T, c net.Conn) error {
|
|||
}
|
||||
|
||||
func testPingPongWithPacketConn(t *testing.T, pc net.PacketConn) error {
|
||||
l, err := net.ListenPacket("udp", ":10001")
|
||||
l, err := ListenPacket("udp", ":10001")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ type hashPair struct {
|
|||
}
|
||||
|
||||
func testLargeDataWithConn(t *testing.T, c net.Conn) error {
|
||||
l, err := net.Listen("tcp", ":10001")
|
||||
l, err := Listen("tcp", ":10001")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -438,7 +438,7 @@ func testLargeDataWithConn(t *testing.T, c net.Conn) error {
|
|||
}
|
||||
|
||||
func testLargeDataWithPacketConn(t *testing.T, pc net.PacketConn) error {
|
||||
l, err := net.ListenPacket("udp", ":10001")
|
||||
l, err := ListenPacket("udp", ":10001")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -622,7 +622,7 @@ func testSuit(t *testing.T, proxy C.ProxyAdapter) {
|
|||
}
|
||||
|
||||
func benchmarkProxy(b *testing.B, proxy C.ProxyAdapter) {
|
||||
l, err := net.Listen("tcp", ":10001")
|
||||
l, err := Listen("tcp", ":10001")
|
||||
if err != nil {
|
||||
assert.FailNow(b, err.Error())
|
||||
}
|
||||
|
@ -639,6 +639,7 @@ func benchmarkProxy(b *testing.B, proxy C.ProxyAdapter) {
|
|||
|
||||
chunkSize := int64(16 * 1024)
|
||||
chunk := make([]byte, chunkSize)
|
||||
rand.Read(chunk)
|
||||
conn, err := proxy.DialContext(context.Background(), &C.Metadata{
|
||||
Host: localIP.String(),
|
||||
DstPort: "10001",
|
||||
|
|
37
test/util.go
Normal file
37
test/util.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Listen(network, address string) (net.Listener, error) {
|
||||
lc := net.ListenConfig{}
|
||||
|
||||
var lastErr error
|
||||
for i := 0; i < 5; i++ {
|
||||
l, err := lc.Listen(context.Background(), network, address)
|
||||
if err == nil {
|
||||
return l, nil
|
||||
}
|
||||
|
||||
lastErr = err
|
||||
time.Sleep(time.Millisecond * 200)
|
||||
}
|
||||
return nil, lastErr
|
||||
}
|
||||
|
||||
func ListenPacket(network, address string) (net.PacketConn, error) {
|
||||
var lastErr error
|
||||
for i := 0; i < 5; i++ {
|
||||
l, err := net.ListenPacket(network, address)
|
||||
if err == nil {
|
||||
return l, nil
|
||||
}
|
||||
|
||||
lastErr = err
|
||||
time.Sleep(time.Millisecond * 200)
|
||||
}
|
||||
return nil, lastErr
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
//go:build !darwin
|
||||
// +build !darwin
|
||||
|
||||
package main
|
||||
|
|
Loading…
Reference in a new issue