mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
p2p/discover: fix flaky test which wrote to test.log after completion
This commit is contained in:
parent
80b529ea71
commit
9e56ade561
2 changed files with 23 additions and 3 deletions
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"slices"
|
"slices"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
|
@ -75,7 +76,12 @@ func TestUDPv4_LookupIterator(t *testing.T) {
|
||||||
bootnodes[i] = lookupTestnet.node(256, i)
|
bootnodes[i] = lookupTestnet.node(256, i)
|
||||||
}
|
}
|
||||||
fillTable(test.table, bootnodes, true)
|
fillTable(test.table, bootnodes, true)
|
||||||
go serveTestnet(test, lookupTestnet)
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
serveTestnet(test, lookupTestnet)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
// Create the iterator and collect the nodes it yields.
|
// Create the iterator and collect the nodes it yields.
|
||||||
iter := test.udp.RandomNodes()
|
iter := test.udp.RandomNodes()
|
||||||
|
|
@ -95,6 +101,8 @@ func TestUDPv4_LookupIterator(t *testing.T) {
|
||||||
if err := checkNodesEqual(results, want); err != nil {
|
if err := checkNodesEqual(results, want); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
test.close()
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestUDPv4_LookupIteratorClose checks that lookupIterator ends when its Close
|
// TestUDPv4_LookupIteratorClose checks that lookupIterator ends when its Close
|
||||||
|
|
@ -110,7 +118,13 @@ func TestUDPv4_LookupIteratorClose(t *testing.T) {
|
||||||
bootnodes[i] = lookupTestnet.node(256, i)
|
bootnodes[i] = lookupTestnet.node(256, i)
|
||||||
}
|
}
|
||||||
fillTable(test.table, bootnodes, true)
|
fillTable(test.table, bootnodes, true)
|
||||||
go serveTestnet(test, lookupTestnet)
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
serveTestnet(test, lookupTestnet)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
it := test.udp.RandomNodes()
|
it := test.udp.RandomNodes()
|
||||||
if ok := it.Next(); !ok || it.Node() == nil {
|
if ok := it.Next(); !ok || it.Node() == nil {
|
||||||
|
|
@ -132,6 +146,8 @@ func TestUDPv4_LookupIteratorClose(t *testing.T) {
|
||||||
if n := it.Node(); n != nil {
|
if n := it.Node(); n != nil {
|
||||||
t.Errorf("iterator returned non-nil node after close and %d more calls", ncalls)
|
t.Errorf("iterator returned non-nil node after close and %d more calls", ncalls)
|
||||||
}
|
}
|
||||||
|
test.close()
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveTestnet(test *udpTest, testnet *preminedTestnet) {
|
func serveTestnet(test *udpTest, testnet *preminedTestnet) {
|
||||||
|
|
|
||||||
|
|
@ -496,6 +496,10 @@ func nextNode(it iterator.Iterator) *Node {
|
||||||
|
|
||||||
// Close flushes and closes the database files.
|
// Close flushes and closes the database files.
|
||||||
func (db *DB) Close() {
|
func (db *DB) Close() {
|
||||||
close(db.quit)
|
select {
|
||||||
|
case <-db.quit: // already closed
|
||||||
|
default:
|
||||||
|
close(db.quit)
|
||||||
|
}
|
||||||
db.lvl.Close()
|
db.lvl.Close()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue