mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00: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:
parent
c1a54ae58e
commit
94c249a8c8
6 changed files with 241 additions and 159 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue