Fix timing sensitive tests

pull/148/head
Andy Wang 3 years ago
parent 275540a793
commit 005da456c0
No known key found for this signature in database
GPG Key ID: 181B49F9F38F3374

@ -1,10 +0,0 @@
language: go
go:
- "1.15"
script:
- go test -race -coverprofile=coverage.txt -coverpkg=./... -covermode=atomic ./...
after_success:
- bash <(curl -s https://codecov.io/bash)

@ -76,7 +76,7 @@ func TestDatagramBuffer_BlockingRead(t *testing.T) {
pipe := NewDatagramBufferedPipe()
b := []byte{0x01, 0x02, 0x03}
go func() {
time.Sleep(100 * time.Millisecond)
time.Sleep(readBlockTime)
pipe.Write(Frame{Payload: b})
}()
b2 := make([]byte, len(b))

@ -12,6 +12,8 @@ import (
"time"
)
const eventualConsistencyTolerance = 500 * time.Millisecond
func serveEcho(l net.Listener) {
for {
conn, err := l.Accept()
@ -111,6 +113,8 @@ func TestMultiplex(t *testing.T) {
//test echo
runEchoTest(t, streams, maxMsgLen)
time.Sleep(eventualConsistencyTolerance)
if clientSession.streamCount() != numStreams {
t.Errorf("client stream count is wrong: %v", clientSession.streamCount())
}
@ -148,7 +152,7 @@ func TestMux_StreamClosing(t *testing.T) {
t.Errorf("can't write to stream: %v", err)
}
time.Sleep(500 * time.Millisecond)
time.Sleep(eventualConsistencyTolerance)
_ = toBeClosed.Close()
_, err = io.ReadFull(toBeClosed, recvBuf)
if err != nil {

@ -408,7 +408,7 @@ func TestSession_timeoutAfter(t *testing.T) {
seshConfigOrdered.Obfuscator = obfuscator
seshConfigOrdered.InactivityTimeout = 100 * time.Millisecond
sesh := MakeSession(0, seshConfigOrdered)
time.Sleep(200 * time.Millisecond)
time.Sleep(2 * seshConfigOrdered.InactivityTimeout)
if !sesh.IsClosed() {
t.Error("session should have timed out")
}

@ -7,6 +7,8 @@ import (
"time"
)
const readBlockTime = 500 * time.Millisecond
func TestPipeRW(t *testing.T) {
pipe := NewStreamBufferedPipe()
b := []byte{0x01, 0x02, 0x03}
@ -60,7 +62,7 @@ func TestReadBlock(t *testing.T) {
pipe := NewStreamBufferedPipe()
b := []byte{0x01, 0x02, 0x03}
go func() {
time.Sleep(100 * time.Millisecond)
time.Sleep(readBlockTime)
pipe.Write(b)
}()
b2 := make([]byte, len(b))

@ -230,7 +230,7 @@ func TestStream_Close(t *testing.T) {
if err != nil {
t.Errorf("can't read residual data %v", err)
}
time.Sleep(100 * time.Millisecond)
time.Sleep(eventualConsistencyTolerance)
if sI, _ := sesh.streams.Load(stream.(*Stream).id); sI != nil {
t.Error("stream still exists")
return

@ -145,7 +145,7 @@ func TestSwitchboard_CloseOnOneDisconn(t *testing.T) {
sesh.AddConnection(conn1client)
conn0server.Close()
time.Sleep(500 * time.Millisecond)
time.Sleep(eventualConsistencyTolerance)
if !sesh.IsClosed() {
t.Error("session not closed after one conn is disconnected")
return
@ -178,7 +178,7 @@ func TestSwitchboard_ConnsCount(t *testing.T) {
sesh.sb.closeAll()
time.Sleep(500 * time.Millisecond)
time.Sleep(eventualConsistencyTolerance)
if sesh.sb.connsCount() != 0 {
t.Error("connsCount incorrect")
}

Loading…
Cancel
Save