Skip to content

Commit 4076744

Browse files
fix cli tests with enabled Provide Sweep
1 parent 7b3d098 commit 4076744

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

test/cli/delegated_routing_v1_http_proxy_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ func TestRoutingV1Proxy(t *testing.T) {
7272

7373
cidStr := nodes[0].IPFSAddStr(string(random.Bytes(1000)))
7474
// Reprovide as initialProviderDelay still ongoing
75-
res := nodes[0].IPFS("routing", "reprovide")
76-
require.NoError(t, res.Err)
77-
res = nodes[1].IPFS("routing", "findprovs", cidStr)
75+
waitUntilProvidesComplete(t, nodes[0])
76+
77+
res := nodes[1].IPFS("routing", "findprovs", cidStr)
7878
assert.Equal(t, nodes[0].PeerID().String(), res.Stdout.Trimmed())
7979
})
8080

test/cli/delegated_routing_v1_http_server_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/ipfs/kubo/test/cli/harness"
1515
"github.com/libp2p/go-libp2p/core/peer"
1616
"github.com/stretchr/testify/assert"
17-
"github.com/stretchr/testify/require"
1817
)
1918

2019
func TestRoutingV1Server(t *testing.T) {
@@ -39,9 +38,7 @@ func TestRoutingV1Server(t *testing.T) {
3938
text := "hello world " + uuid.New().String()
4039
cidStr := nodes[2].IPFSAddStr(text)
4140
_ = nodes[3].IPFSAddStr(text)
42-
// Reprovide as initialProviderDelay still ongoing
43-
res := nodes[3].IPFS("routing", "reprovide")
44-
require.NoError(t, res.Err)
41+
waitUntilProvidesComplete(t, nodes[3])
4542

4643
cid, err := cid.Decode(cidStr)
4744
assert.NoError(t, err)

test/cli/routing_dht_test.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,44 @@ package cli
22

33
import (
44
"fmt"
5+
"strconv"
6+
"strings"
57
"testing"
8+
"time"
69

710
"github.com/ipfs/kubo/test/cli/harness"
811
"github.com/ipfs/kubo/test/cli/testutils"
912
"github.com/stretchr/testify/assert"
1013
"github.com/stretchr/testify/require"
1114
)
1215

16+
func waitUntilProvidesComplete(t *testing.T, n *harness.Node) {
17+
getCidsCount := func(line string) int {
18+
trimmed := strings.TrimSpace(line)
19+
countStr := strings.SplitN(trimmed, " ", 2)[0]
20+
count, err := strconv.Atoi(countStr)
21+
require.NoError(t, err)
22+
return count
23+
}
24+
25+
queuedProvides, ongoingProvides := true, true
26+
for queuedProvides || ongoingProvides {
27+
res := n.IPFS("provide", "stat", "-a")
28+
require.NoError(t, res.Err)
29+
for _, line := range res.Stdout.Lines() {
30+
if trimmed, ok := strings.CutPrefix(line, " Provide queue:"); ok {
31+
provideQueueSize := getCidsCount(trimmed)
32+
queuedProvides = provideQueueSize > 0
33+
}
34+
if trimmed, ok := strings.CutPrefix(line, " Ongoing provides:"); ok {
35+
ongoingProvideCount := getCidsCount(trimmed)
36+
ongoingProvides = ongoingProvideCount > 0
37+
}
38+
}
39+
time.Sleep(10 * time.Millisecond)
40+
}
41+
}
42+
1343
func testRoutingDHT(t *testing.T, enablePubsub bool) {
1444
t.Run(fmt.Sprintf("enablePubSub=%v", enablePubsub), func(t *testing.T) {
1545
t.Parallel()
@@ -84,10 +114,8 @@ func testRoutingDHT(t *testing.T, enablePubsub bool) {
84114
t.Run("ipfs routing findprovs", func(t *testing.T) {
85115
t.Parallel()
86116
hash := nodes[3].IPFSAddStr("some stuff")
87-
// Reprovide as initialProviderDelay still ongoing
88-
res := nodes[3].IPFS("routing", "reprovide")
89-
require.NoError(t, res.Err)
90-
res = nodes[4].IPFS("routing", "findprovs", hash)
117+
waitUntilProvidesComplete(t, nodes[3])
118+
res := nodes[4].IPFS("routing", "findprovs", hash)
91119
assert.Equal(t, nodes[3].PeerID().String(), res.Stdout.Trimmed())
92120
})
93121

0 commit comments

Comments
 (0)