Skip to content

Commit 09c631e

Browse files
fix: flaky TestSearchValue (dual) (#1038)
* add verbose to flaky TestSearchValue (dual) * fix: flaky TestSearchValue (dual) * reduce verbosity in TestRefresh
1 parent 0a08e52 commit 09c631e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

dht_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -853,11 +853,6 @@ func TestRefresh(t *testing.T) {
853853

854854
time.Sleep(time.Microsecond * 50)
855855
}
856-
857-
if testing.Verbose() {
858-
// the routing tables should be full now. let's inspect them.
859-
printRoutingTables(dhts)
860-
}
861856
}
862857

863858
func TestRefreshBelowMinRTThreshold(t *testing.T) {

dual/dual_test.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
dht "github.com/libp2p/go-libp2p-kad-dht"
1010
"github.com/libp2p/go-libp2p-kad-dht/internal"
1111
test "github.com/libp2p/go-libp2p-kad-dht/internal/testing"
12+
kb "github.com/libp2p/go-libp2p-kbucket"
1213
record "github.com/libp2p/go-libp2p-record"
1314
"github.com/libp2p/go-libp2p/core/host"
1415
"github.com/libp2p/go-libp2p/core/peer"
@@ -119,7 +120,7 @@ func connect(ctx context.Context, t *testing.T, a, b *dht.IpfsDHT) {
119120
if len(baddr) == 0 {
120121
t.Fatal("no addresses for connection.")
121122
}
122-
a.Host().Peerstore().AddAddrs(bid, baddr, peerstore.TempAddrTTL)
123+
a.Host().Peerstore().AddAddrs(bid, baddr, peerstore.AddressTTL)
123124
if err := a.Host().Connect(ctx, peer.AddrInfo{ID: bid}); err != nil {
124125
t.Fatal(err)
125126
}
@@ -179,6 +180,7 @@ func setupTier(ctx context.Context, t *testing.T) (*DHT, *dht.IpfsDHT, *dht.Ipfs
179180
}
180181
hlprs[1].allow = lan.PeerID()
181182
connect(ctx, t, d.LAN, lan)
183+
connect(ctx, t, lan, d.LAN)
182184

183185
return d, wan, lan
184186
}
@@ -285,7 +287,13 @@ func TestSearchValue(t *testing.T) {
285287
d.WAN.Validator.(record.NamespacedValidator)["v"] = test.TestValidator{}
286288
d.LAN.Validator.(record.NamespacedValidator)["v"] = test.TestValidator{}
287289

288-
_ = wan.PutValue(ctx, "/v/hello", []byte("valid"))
290+
err := wan.PutValue(ctx, "/v/hello", []byte("valid"))
291+
// it is expected that we get an ErrLookupFailure here, because wan doesn't
292+
// have any peers in its routing table (d.WAN is a client). this operation
293+
// still puts the record in wan local datastore, which is what we want.
294+
if err != kb.ErrLookupFailure {
295+
t.Error("error putting value to wan DHT:", err)
296+
}
289297

290298
valCh, err := d.SearchValue(ctx, "/v/hello", dht.Quorum(0))
291299
if err != nil {
@@ -312,7 +320,7 @@ func TestSearchValue(t *testing.T) {
312320

313321
err = lan.PutValue(ctx, "/v/hello", []byte("newer"))
314322
if err != nil {
315-
t.Error(err)
323+
t.Error("error putting value to lan DHT:", err)
316324
}
317325

318326
valCh, err = d.SearchValue(ctx, "/v/hello", dht.Quorum(0))

0 commit comments

Comments
 (0)