Commit 9b47c884 authored by Steven Allen's avatar Steven Allen

test: deflake keepalive

parent 9f75d694
......@@ -2,4 +2,7 @@ module github.com/libp2p/go-yamux/v2
go 1.15
require github.com/libp2p/go-buffer-pool v0.0.2
require (
github.com/libp2p/go-buffer-pool v0.0.2
github.com/stretchr/testify v1.7.0
)
......@@ -14,6 +14,8 @@ import (
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/require"
)
type logCapture struct{ bytes.Buffer }
......@@ -1005,20 +1007,18 @@ func TestKeepAlive(t *testing.T) {
defer client.Close()
defer server.Close()
time.Sleep(200 * time.Millisecond)
// Ping value should increase
client.pingLock.Lock()
defer client.pingLock.Unlock()
if client.pingID == 0 {
t.Fatalf("should ping")
}
server.pingLock.Lock()
defer server.pingLock.Unlock()
if server.pingID == 0 {
t.Fatalf("should ping")
}
require.Eventually(t, func() bool {
client.pingLock.Lock()
defer client.pingLock.Unlock()
return client.pingID > 0
}, time.Second, 50*time.Millisecond, "should ping")
require.Eventually(t, func() bool {
server.pingLock.Lock()
defer server.pingLock.Unlock()
return server.pingID > 0
}, time.Second, 50*time.Millisecond, "should ping")
}
func TestKeepAlive_Timeout(t *testing.T) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment