mirror of https://github.com/cbeuw/Cloak
Allow retries in time sensitive tests
This commit is contained in:
parent
ef040b0115
commit
c564114f76
|
|
@ -23,7 +23,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const numConns = 200 // -race option limits the number of goroutines to 8192
|
const numConns = 200 // -race option limits the number of goroutines to 8192
|
||||||
const delayBeforeTestingConnClose = 700 * time.Millisecond
|
const delayBeforeTestingConnClose = 500 * time.Millisecond
|
||||||
|
const connCloseRetries = 3
|
||||||
|
|
||||||
func serveTCPEcho(l net.Listener) {
|
func serveTCPEcho(l net.Listener) {
|
||||||
for {
|
for {
|
||||||
|
|
@ -353,9 +354,17 @@ func TestTCPSingleplex(t *testing.T) {
|
||||||
runEchoTest(t, []net.Conn{proxyConn1, proxyConn2}, 65536)
|
runEchoTest(t, []net.Conn{proxyConn1, proxyConn2}, 65536)
|
||||||
|
|
||||||
proxyConn1.Close()
|
proxyConn1.Close()
|
||||||
|
|
||||||
|
retries := 0
|
||||||
|
retry:
|
||||||
time.Sleep(delayBeforeTestingConnClose)
|
time.Sleep(delayBeforeTestingConnClose)
|
||||||
if user.NumSession() != 1 {
|
if user.NumSession() != 1 {
|
||||||
|
retries++
|
||||||
|
if retries > connCloseRetries {
|
||||||
t.Error("first session was not closed on connection close")
|
t.Error("first session was not closed on connection close")
|
||||||
|
} else {
|
||||||
|
goto retry
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// conn2 should still work
|
// conn2 should still work
|
||||||
|
|
@ -469,9 +478,16 @@ func TestClosingStreamsFromProxy(t *testing.T) {
|
||||||
serverConn, _ := proxyFromCkServerL.Accept()
|
serverConn, _ := proxyFromCkServerL.Accept()
|
||||||
serverConn.Close()
|
serverConn.Close()
|
||||||
|
|
||||||
|
retries := 0
|
||||||
|
retry:
|
||||||
time.Sleep(delayBeforeTestingConnClose)
|
time.Sleep(delayBeforeTestingConnClose)
|
||||||
if _, err := clientConn.Read(make([]byte, 16)); err == nil {
|
if _, err := clientConn.Read(make([]byte, 16)); err == nil {
|
||||||
|
retries++
|
||||||
|
if retries > connCloseRetries {
|
||||||
t.Errorf("closing stream on server side is not reflected to the client: %v", err)
|
t.Errorf("closing stream on server side is not reflected to the client: %v", err)
|
||||||
|
} else {
|
||||||
|
goto retry
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -482,9 +498,16 @@ func TestClosingStreamsFromProxy(t *testing.T) {
|
||||||
serverConn, _ := proxyFromCkServerL.Accept()
|
serverConn, _ := proxyFromCkServerL.Accept()
|
||||||
clientConn.Close()
|
clientConn.Close()
|
||||||
|
|
||||||
|
retries := 0
|
||||||
|
retry:
|
||||||
time.Sleep(delayBeforeTestingConnClose)
|
time.Sleep(delayBeforeTestingConnClose)
|
||||||
if _, err := serverConn.Read(make([]byte, 16)); err == nil {
|
if _, err := serverConn.Read(make([]byte, 16)); err == nil {
|
||||||
|
retries++
|
||||||
|
if retries > 3 {
|
||||||
t.Errorf("closing stream on client side is not reflected to the server: %v", err)
|
t.Errorf("closing stream on client side is not reflected to the server: %v", err)
|
||||||
|
} else {
|
||||||
|
goto retry
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -496,8 +519,8 @@ func TestClosingStreamsFromProxy(t *testing.T) {
|
||||||
clientConn.Write(testData)
|
clientConn.Write(testData)
|
||||||
// it takes time for this written data to be copied asynchronously
|
// it takes time for this written data to be copied asynchronously
|
||||||
// into ck-server's domain. If the pipe is closed before that, read
|
// into ck-server's domain. If the pipe is closed before that, read
|
||||||
// by ck-client in RoutTCP will fail as we have closed it.
|
// by ck-client in RouteTCP will fail as we have closed it.
|
||||||
time.Sleep(delayBeforeTestingConnClose)
|
time.Sleep(700 * time.Millisecond)
|
||||||
clientConn.Close()
|
clientConn.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue