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. // they have all found each other.
status := make(chan error, len(nodes)) status := make(chan error, len(nodes))
for i := range nodes { for i := range nodes {
node := nodes[i] self := nodes[i]
go func() { go func() {
found := make(map[enode.ID]bool, len(nodes)) missing := make(map[enode.ID]bool, len(nodes))
it := node.RandomNodes() 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() { for it.Next() {
found[it.Node().ID()] = true fmt.Println(self.Self().ID(), "found:", it.Node().ID())
if len(found) == len(nodes) { delete(missing, it.Node().ID())
if len(missing) == 0 {
status <- nil status <- nil
return 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++ received++
if err != nil { if err != nil {
t.Error("ERROR:", err) t.Error("ERROR:", err)
return
} }
} }
} }