p2p/discover: track missing nodes in test

This commit is contained in:
Felix Lange 2025-09-05 14:16:51 +02:00
parent 721c8de738
commit cf0503da7c

View file

@ -509,18 +509,27 @@ func TestUDPv4_smallNetConvergence(t *testing.T) {
// they have all found each other.
status := make(chan error, len(nodes))
for i := range nodes {
node := nodes[i]
self := nodes[i]
go func() {
found := make(map[enode.ID]bool, len(nodes))
it := node.RandomNodes()
missing := make(map[enode.ID]bool, len(nodes))
for _, n := range nodes {
if n.Self().ID() == self.Self().ID() {
continue // skip self
}
missing[n.Self().ID()] = true
}
it := self.RandomNodes()
for it.Next() {
found[it.Node().ID()] = true
if len(found) == len(nodes) {
fmt.Println(self.Self().ID(), "found:", it.Node().ID())
delete(missing, it.Node().ID())
if len(missing) == 0 {
status <- nil
return
}
}
status <- fmt.Errorf("node %s didn't find all nodes", node.Self().ID().TerminalString())
missingIDs := slices.Collect(maps.Keys(missing))
status <- fmt.Errorf("node %s didn't find all nodes, missing %v", self.Self().ID().TerminalString(), missingIDs)
}()
}
@ -537,7 +546,6 @@ func TestUDPv4_smallNetConvergence(t *testing.T) {
received++
if err != nil {
t.Error("ERROR:", err)
return
}
}
}