From 9bd2214c2d6f2b3ee510a492a54e2a264aa08038 Mon Sep 17 00:00:00 2001 From: acud <12988138+acud@users.noreply.github.com> Date: Wed, 4 Nov 2026 10:34:52 -0600 Subject: [PATCH] test(kademlia): re-enable TestClosestPeer and TestNotifierHooks TestClosestPeer panicked with index out of range when un-skipped: the node was never marked publicly reachable, so ClosestPeer did not consider self and the want-self case fell through to connectedPeers[-1]. Set the reachability in setup and assert errors explicitly, rather than ignoring them for cases that expect a peer. TestNotifierHooks passes unchanged, so only its skip is removed. Co-Authored-By: Claude Opus 5.5 --- pkg/topology/kademlia/kademlia_test.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/topology/kademlia/kademlia_test.go b/pkg/topology/kademlia/kademlia_test.go index 008a0611cf8..046583a3181 100644 --- a/pkg/topology/kademlia/kademlia_test.go +++ b/pkg/topology/kademlia/kademlia_test.go @@ -668,7 +668,6 @@ func TestBootnodeMaxConnections(t *testing.T) { // result in the correct behavior once called. func TestNotifierHooks(t *testing.T) { t.Parallel() - t.Skip("disabled due to kademlia inconsistencies hotfix") var ( base, kad, ab, _, signer = newTestKademlia(t, nil, nil, kademlia.Options{}) @@ -961,9 +960,6 @@ func TestAddressBookQuickPrune(t *testing.T) { func TestClosestPeer(t *testing.T) { t.Parallel() - t.Skip("disabled due to kademlia inconsistencies hotfix") - - _ = waitPeers logger := log.Noop base := swarm.MustParseHexAddress("0000000000000000000000000000000000000000000000000000000000000000") // base is 0000 @@ -1008,6 +1004,9 @@ func TestClosestPeer(t *testing.T) { waitPeers(t, kad, 3) + // ClosestPeer only considers self when the node is publicly reachable. + kad.UpdateReachability(p2p.ReachabilityStatusPublic) + for _, tc := range []struct { chunkAddress swarm.Address // chunk address to test expectedPeer int // points to the index of the connectedPeers slice. -1 means self (baseOverlay) @@ -1055,12 +1054,15 @@ func TestClosestPeer(t *testing.T) { }, } { peer, err := kad.ClosestPeer(tc.chunkAddress, tc.includeSelf, topology.Select{}) - if err != nil { - if tc.expectedPeer == -1 && !errors.Is(err, topology.ErrWantSelf) { + if tc.expectedPeer == -1 { + if !errors.Is(err, topology.ErrWantSelf) { t.Fatalf("wanted %v but got %v", topology.ErrWantSelf, err) } continue } + if err != nil { + t.Fatalf("closest peer for %s: %v", tc.chunkAddress, err) + } expected := connectedPeers[tc.expectedPeer].Address