Skip to content

Commit

Permalink
fix: do not return cached results for FindPeers
Browse files Browse the repository at this point in the history
  • Loading branch information
2color committed Dec 11, 2024
1 parent 2211aae commit be5958a
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions server_cached_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestCachedRouter(t *testing.T) {
require.Equal(t, publicAddr.String(), peerRecord.Addrs[0].String())
})

t.Run("FindPeers with cache hit", func(t *testing.T) {
t.Run("Failed FindPeers with cached addresses does not return cached addresses", func(t *testing.T) {
ctx := context.Background()
pid := peer.ID("test-peer")

Expand All @@ -106,17 +106,8 @@ func TestCachedRouter(t *testing.T) {
// Create cached router
cr := NewCachedRouter(mr, cab)

it, err := cr.FindPeers(ctx, pid, 10)
require.NoError(t, err)

results, err := iter.ReadAllResults(it)
require.NoError(t, err)
require.Len(t, results, 1)

// Verify cached addresses were returned
require.Equal(t, pid, *results[0].ID)
require.Len(t, results[0].Addrs, 1)
require.Equal(t, publicAddr.String(), results[0].Addrs[0].String())
_, err = cr.FindPeers(ctx, pid, 10)
require.ErrorIs(t, err, routing.ErrNotFound)
})

t.Run("FindPeers with cache miss", func(t *testing.T) {
Expand Down

0 comments on commit be5958a

Please sign in to comment.