Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deflake resource manager tests, take 2 #1318

Merged
merged 1 commit into from
Feb 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions itest/rcmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (
rcmgr "github.com/libp2p/go-libp2p-resource-manager"

"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"

"github.com/stretchr/testify/require"
)

func makeRcmgrOption(t *testing.T, limiter *rcmgr.BasicLimiter, test string) func(int) libp2p.Option {
Expand All @@ -37,12 +40,19 @@ func closeRcmgrs(echos []*Echo) {
}
}

func waitForConnection(t *testing.T, src, dest *Echo) {
require.Eventually(t, func() bool {
return src.Host.Network().Connectedness(dest.Host.ID()) == network.Connected &&
dest.Host.Network().Connectedness(src.Host.ID()) == network.Connected
}, time.Second, time.Millisecond)
}

func TestResourceManagerConnInbound(t *testing.T) {
// this test checks that we can not exceed the inbound conn limit at system level
// we specify: 1 conn per peer, 3 conns total, and we try to create 4 conns
limiter := rcmgr.NewDefaultLimiter()
limiter.SystemLimits = limiter.SystemLimits.WithConnLimit(3, 1024, 1024)
limiter.DefaultPeerLimits = limiter.DefaultPeerLimits.WithConnLimit(1, 16, 16)
limiter.DefaultPeerLimits = limiter.DefaultPeerLimits.WithConnLimit(1, 1, 1)

echos := createEchos(t, 5, makeRcmgrOption(t, limiter, "TestResourceManagerConnInbound"))
defer closeEchos(echos)
Expand All @@ -53,7 +63,7 @@ func TestResourceManagerConnInbound(t *testing.T) {
if err != nil {
t.Fatal(err)
}
time.Sleep(10 * time.Millisecond)
waitForConnection(t, echos[i], echos[0])
}

for i := 1; i < 4; i++ {
Expand All @@ -74,7 +84,7 @@ func TestResourceManagerConnOutbound(t *testing.T) {
// we specify: 1 conn per peer, 3 conns total, and we try to create 4 conns
limiter := rcmgr.NewDefaultLimiter()
limiter.SystemLimits = limiter.SystemLimits.WithConnLimit(1024, 3, 1024)
limiter.DefaultPeerLimits = limiter.DefaultPeerLimits.WithConnLimit(16, 1, 16)
limiter.DefaultPeerLimits = limiter.DefaultPeerLimits.WithConnLimit(1, 1, 1)
echos := createEchos(t, 5, makeRcmgrOption(t, limiter, "TestResourceManagerConnOutbound"))
defer closeEchos(echos)
defer closeRcmgrs(echos)
Expand All @@ -84,7 +94,7 @@ func TestResourceManagerConnOutbound(t *testing.T) {
if err != nil {
t.Fatal(err)
}
time.Sleep(10 * time.Millisecond)
waitForConnection(t, echos[0], echos[i])
}

for i := 1; i < 4; i++ {
Expand Down Expand Up @@ -114,7 +124,7 @@ func TestResourceManagerServiceInbound(t *testing.T) {
if err != nil {
t.Fatal(err)
}
time.Sleep(10 * time.Millisecond)
waitForConnection(t, echos[i], echos[0])
}

ready := make(chan struct{})
Expand Down Expand Up @@ -167,7 +177,7 @@ func TestResourceManagerServicePeerInbound(t *testing.T) {
if err != nil {
t.Fatal(err)
}
time.Sleep(10 * time.Millisecond)
waitForConnection(t, echos[i], echos[0])
}

echos[0].BeforeDone(waitForBarrier(4, time.Minute))
Expand Down