@@ -2,14 +2,44 @@ package cli
22
33import (
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+
1343func 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