test: fix flaky rcmgr test
Gus Eggert committed
Mar 15, 2023 at 14:57 UTC
684d9dc79fce8d899ea1c5b97a7400526fc1d28f
2 files changed
+20
-1
test/cli/rcmgr_test.go
+5
-1
@@ -7,6 +7,7 @@ import (
7
"github.com/ipfs/kubo/config"
8
"github.com/ipfs/kubo/core/node/libp2p"
9
"github.com/ipfs/kubo/test/cli/harness"
10
+ "github.com/ipfs/kubo/test/cli/testutils"
11
"github.com/libp2p/go-libp2p/core/peer"
12
"github.com/libp2p/go-libp2p/core/protocol"
13
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
@@ -209,7 +210,10 @@ func TestRcmgr(t *testing.T) {
210
Args: []string{"swarm", "connect", node1.SwarmAddrsWithPeerIDs()[0].String()},
211
})
212
assert.Equal(t, 1, res.ExitCode())
212
- assert.Contains(t, res.Stderr.String(), "failed to find any peer in table")
213
+ testutils.AssertStringContainsOneOf(t, res.Stderr.String(),
214
+ "failed to find any peer in table",
215
+ "resource limit exceeded",
216
+ )
217
218
res = node0.RunIPFS("ping", "-n2", peerID1)
219
assert.Equal(t, 1, res.ExitCode())
test/cli/testutils/asserts.go
new
+15
@@ -0,0 +1,15 @@
1
+package testutils
2
+
3
+import (
4
+ "strings"
5
+ "testing"
6
+)
7
+
8
+func AssertStringContainsOneOf(t *testing.T, str string, ss ...string) {
9
+ for _, s := range ss {
10
+ if strings.Contains(str, s) {
11
+ return
12
+ }
13
+ }
14
+ t.Errorf("%q does not contain one of %v", str, ss)
15
+}