From 3eab4616a69bc313a94f073e24cd5093b0dc922b Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Fri, 12 Sep 2025 10:59:29 +0200 Subject: [PATCH] p2p/discover: add test for lookup returning immediately Signed-off-by: Csaba Kiraly --- p2p/discover/v4_lookup_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/p2p/discover/v4_lookup_test.go b/p2p/discover/v4_lookup_test.go index 29a9dd6645..88ca82039e 100644 --- a/p2p/discover/v4_lookup_test.go +++ b/p2p/discover/v4_lookup_test.go @@ -23,6 +23,7 @@ import ( "slices" "sync" "testing" + "time" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/p2p/discover/v4wire" @@ -34,11 +35,15 @@ func TestUDPv4_Lookup(t *testing.T) { t.Parallel() test := newUDPTest(t) - // Lookup on empty table returns no nodes. + // Lookup on empty table returns immediately with no nodes. targetKey, _ := v4wire.DecodePubkey(crypto.S256(), lookupTestnet.target) + start := time.Now() if results := test.udp.LookupPubkey(targetKey); len(results) > 0 { t.Fatalf("lookup on empty table returned %d results: %#v", len(results), results) } + if time.Since(start) > 100*time.Millisecond { + t.Fatalf("lookup on empty table took too long: %s", time.Since(start)) + } // Seed table with initial node. fillTable(test.table, []*enode.Node{lookupTestnet.node(256, 0)}, true)