mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-23 08:19:27 +00:00
p2p/discover: fix TestUDPv4_findnode data race with revalidation ping
This commit is contained in:
parent
0413af40f6
commit
88fb6825d5
1 changed files with 23 additions and 11 deletions
|
|
@ -281,8 +281,17 @@ func TestUDPv4_findnode(t *testing.T) {
|
||||||
// check that closest neighbors are returned.
|
// check that closest neighbors are returned.
|
||||||
expected := test.table.findnodeByID(testTarget.ID(), bucketSize, true)
|
expected := test.table.findnodeByID(testTarget.ID(), bucketSize, true)
|
||||||
test.packetIn(nil, &v4wire.Findnode{Target: testTarget, Expiration: futureExp})
|
test.packetIn(nil, &v4wire.Findnode{Target: testTarget, Expiration: futureExp})
|
||||||
waitNeighbors := func(want []*enode.Node) {
|
deadline := time.Now().Add(1 * time.Minute)
|
||||||
test.waitPacketOut(func(p *v4wire.Neighbors, to netip.AddrPort, hash []byte) {
|
var waitNeighbors func([]*enode.Node)
|
||||||
|
waitNeighbors = func(want []*enode.Node) {
|
||||||
|
if time.Now().After(deadline) {
|
||||||
|
t.Fatal("timeout waiting for neighbors response")
|
||||||
|
}
|
||||||
|
test.waitPacketOut(func(p v4wire.Packet, to netip.AddrPort, hash []byte) {
|
||||||
|
switch p := p.(type) {
|
||||||
|
case *v4wire.Ping:
|
||||||
|
waitNeighbors(want)
|
||||||
|
case *v4wire.Neighbors:
|
||||||
if len(p.Nodes) != len(want) {
|
if len(p.Nodes) != len(want) {
|
||||||
t.Errorf("wrong number of results: got %d, want %d", len(p.Nodes), len(want))
|
t.Errorf("wrong number of results: got %d, want %d", len(p.Nodes), len(want))
|
||||||
return
|
return
|
||||||
|
|
@ -295,6 +304,9 @@ func TestUDPv4_findnode(t *testing.T) {
|
||||||
t.Errorf("result includes dead node %v", n.ID.ID())
|
t.Errorf("result includes dead node %v", n.ID.ID())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
t.Fatalf("unexpected packet type: %T", p)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// Receive replies.
|
// Receive replies.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue