mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-12 03:19:36 +03:00
Fix some flaky tests related to pick port (#985)
* Fix some tests to PickPort correctly * Add retry logic for two socks tests Two socks tests listen for both TCP and UDP with same port number, in some cases the port is not available Add retry logic for server core, start server core and client core separately Extract a common method * Add retry logic for two dokodemo tests Two dokodemo tests listen for 5 ports, in some cases they are not available Add retry logic for client core, start server and client separately
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"runtime"
|
||||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
@ -235,3 +236,20 @@ func testTCPConn2(conn net.Conn, payloadSize int, timeout time.Duration) func()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func WaitConnAvailableWithTest(t *testing.T, testFunc func() error) bool {
|
||||
for i := 1; ; i++ {
|
||||
if i > 10 {
|
||||
t.Log("All attempts failed to test tcp conn")
|
||||
return false
|
||||
}
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
if err := testFunc(); err != nil {
|
||||
t.Log("err ", err)
|
||||
} else {
|
||||
t.Log("success with", i, "attempts")
|
||||
break
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
Reference in New Issue
Block a user