mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-14 12:06:40 +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,19 +281,31 @@ 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)
|
||||||
if len(p.Nodes) != len(want) {
|
waitNeighbors = func(want []*enode.Node) {
|
||||||
t.Errorf("wrong number of results: got %d, want %d", len(p.Nodes), len(want))
|
if time.Now().After(deadline) {
|
||||||
return
|
t.Fatal("timeout waiting for neighbors response")
|
||||||
}
|
}
|
||||||
for i, n := range p.Nodes {
|
test.waitPacketOut(func(p v4wire.Packet, to netip.AddrPort, hash []byte) {
|
||||||
if n.ID.ID() != want[i].ID() {
|
switch p := p.(type) {
|
||||||
t.Errorf("result mismatch at %d:\n got: %v\n want: %v", i, n, expected.entries[i])
|
case *v4wire.Ping:
|
||||||
|
waitNeighbors(want)
|
||||||
|
case *v4wire.Neighbors:
|
||||||
|
if len(p.Nodes) != len(want) {
|
||||||
|
t.Errorf("wrong number of results: got %d, want %d", len(p.Nodes), len(want))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !live[n.ID.ID()] {
|
for i, n := range p.Nodes {
|
||||||
t.Errorf("result includes dead node %v", n.ID.ID())
|
if n.ID.ID() != want[i].ID() {
|
||||||
|
t.Errorf("result mismatch at %d:\n got: %v\n want: %v", i, n, expected.entries[i])
|
||||||
|
}
|
||||||
|
if !live[n.ID.ID()] {
|
||||||
|
t.Errorf("result includes dead node %v", n.ID.ID())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
t.Fatalf("unexpected packet type: %T", p)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue