From 684d9dc79fce8d899ea1c5b97a7400526fc1d28f Mon Sep 17 00:00:00 2001 From: Gus Eggert Date: Wed, 15 Mar 2023 14:57:23 -0400 Subject: [PATCH] test: fix flaky rcmgr test --- test/cli/rcmgr_test.go | 6 +++++- test/cli/testutils/asserts.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/cli/testutils/asserts.go diff --git a/test/cli/rcmgr_test.go b/test/cli/rcmgr_test.go index 51b2b0452..9d76a7dd8 100644 --- a/test/cli/rcmgr_test.go +++ b/test/cli/rcmgr_test.go @@ -7,6 +7,7 @@ import ( "github.com/ipfs/kubo/config" "github.com/ipfs/kubo/core/node/libp2p" "github.com/ipfs/kubo/test/cli/harness" + "github.com/ipfs/kubo/test/cli/testutils" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/protocol" rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" @@ -209,7 +210,10 @@ func TestRcmgr(t *testing.T) { Args: []string{"swarm", "connect", node1.SwarmAddrsWithPeerIDs()[0].String()}, }) assert.Equal(t, 1, res.ExitCode()) - assert.Contains(t, res.Stderr.String(), "failed to find any peer in table") + testutils.AssertStringContainsOneOf(t, res.Stderr.String(), + "failed to find any peer in table", + "resource limit exceeded", + ) res = node0.RunIPFS("ping", "-n2", peerID1) assert.Equal(t, 1, res.ExitCode()) diff --git a/test/cli/testutils/asserts.go b/test/cli/testutils/asserts.go new file mode 100644 index 000000000..cf840c20e --- /dev/null +++ b/test/cli/testutils/asserts.go @@ -0,0 +1,15 @@ +package testutils + +import ( + "strings" + "testing" +) + +func AssertStringContainsOneOf(t *testing.T, str string, ss ...string) { + for _, s := range ss { + if strings.Contains(str, s) { + return + } + } + t.Errorf("%q does not contain one of %v", str, ss) +}