Improve connection timeout

This commit is contained in:
世界
2022-07-18 20:40:14 +08:00
parent 3fb011712b
commit c7fabe40ed
14 changed files with 152 additions and 111 deletions

View File

@@ -35,13 +35,20 @@ func mkPort(t *testing.T) uint16 {
}
func startInstance(t *testing.T, options option.Options) {
instance, err := box.New(context.Background(), options)
var err error
for retry := 0; retry < 3; retry++ {
instance, err := box.New(context.Background(), options)
require.NoError(t, err)
err = instance.Start()
if err != nil {
time.Sleep(5 * time.Millisecond)
continue
}
t.Cleanup(func() {
instance.Close()
})
}
require.NoError(t, err)
require.NoError(t, instance.Start())
t.Cleanup(func() {
instance.Close()
})
time.Sleep(time.Second)
}
func testSuit(t *testing.T, clientPort uint16, testPort uint16) {

View File

@@ -484,7 +484,7 @@ func listen(network, address string) (net.Listener, error) {
}
lastErr = err
time.Sleep(time.Millisecond * 200)
time.Sleep(5 * time.Millisecond)
}
return nil, lastErr
}
@@ -500,7 +500,7 @@ func listenPacket(network, address string) (net.PacketConn, error) {
}
lastErr = err
time.Sleep(time.Millisecond * 200)
time.Sleep(5 * time.Millisecond)
}
return nil, lastErr
}