Skip to content

Commit b733f54

Browse files
committed
feat: make all nodes disconnect just after PEX exchange
Adjust tests to show that PEX is working correctly.
1 parent 5d58009 commit b733f54

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

p2p/pex/pex_reactor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (r *Reactor) Receive(e p2p.Envelope) {
251251

252252
// If we're a seed and this is an inbound peer,
253253
// respond once and disconnect.
254-
if r.config.SeedMode && !e.Src.IsOutbound() {
254+
if /* r.config.SeedMode && */ !e.Src.IsOutbound() {
255255
id := string(e.Src.ID())
256256
v := r.lastReceivedRequests.Get(id)
257257
if v != nil {

p2p/pex/pex_reactor_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ func TestPEXReactorWhenAddressBookIsSmallerThanMaxDials(t *testing.T) {
926926
// not only PEX, but also some test reactors.
927927
// It is asserted that nodes can connect to each other and the address books contain other peers.
928928
func TestPexFromScratch(t *testing.T) {
929+
t.Parallel()
929930
testCases := []struct {
930931
name string
931932
bootstrap int // n - number of bootstrap nodes
@@ -957,9 +958,8 @@ func TestPexFromScratch(t *testing.T) {
957958

958959
sw.SetLogger(logger.With("pex", i))
959960

960-
r := NewReactor(books[i], &ReactorConfig{SeedMode: true})
961+
r := NewReactor(books[i], &ReactorConfig{SeedMode: false})
961962
r.SetLogger(logger.With("pex", i))
962-
r.SetEnsurePeersPeriod(250 * time.Millisecond)
963963
sw.AddReactor("pex", r)
964964

965965
return sw
@@ -1007,15 +1007,18 @@ func TestPexFromScratch(t *testing.T) {
10071007
// assertFullAddressBooks checks if all address books have the expected number of peer entries within a timeout period.
10081008
func assertFullAddressBooks(t *testing.T, totalNodes int, books []AddrBook) {
10091009
var (
1010-
ticker = time.NewTicker(50 * time.Millisecond)
1011-
timeoutCh = time.After(5 * time.Second)
1010+
ticker = time.NewTicker(1 * time.Second)
1011+
timeoutCh = time.After(90 * time.Second)
10121012
)
10131013
defer ticker.Stop()
10141014

10151015
allGood := false
10161016
expected := totalNodes - 1
10171017
for !allGood {
10181018
select {
1019+
case <-timeoutCh:
1020+
t.Errorf("expected all nodes to connect to each other")
1021+
t.FailNow()
10191022
case <-ticker.C:
10201023
// PEX is responsible for address exchange, so we need to check address books, not the number of connections
10211024
// let's make a strong assumption - each node knows of all other nodes
@@ -1030,9 +1033,6 @@ func assertFullAddressBooks(t *testing.T, totalNodes int, books []AddrBook) {
10301033
if cnt == totalNodes {
10311034
allGood = true
10321035
}
1033-
case <-timeoutCh:
1034-
t.Errorf("expected all nodes to connect to each other")
1035-
t.Fail()
10361036
}
10371037
}
10381038
assert.True(t, allGood, "Not all nodes connected to each other")

0 commit comments

Comments
 (0)