From e785697a64c71773e20cc64fbfd9217d3baeef3d Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 6 Nov 2017 23:43:40 -0500 Subject: [PATCH 1/2] connect first switch to others (Refs #808) --- p2p/switch.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/p2p/switch.go b/p2p/switch.go index af9324a9..6cbca767 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -509,10 +509,8 @@ func MakeConnectedSwitches(cfg *cfg.P2PConfig, n int, initSwitch func(int, *Swit panic(err) } - for i := 0; i < n; i++ { - for j := i; j < n; j++ { - connect(switches, i, j) - } + for i := 1; i < n; i++ { + connect(switches, 0, i) } return switches From 7869e541f6a73d96d54fbcca7b7d95185888e935 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 7 Nov 2017 18:31:46 -0500 Subject: [PATCH 2/2] change MakeConnectedSwitches to not connect to itself and a test for it --- p2p/switch.go | 6 ++++-- p2p/switch_test.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/p2p/switch.go b/p2p/switch.go index 6cbca767..c5f71b9b 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -509,8 +509,10 @@ func MakeConnectedSwitches(cfg *cfg.P2PConfig, n int, initSwitch func(int, *Swit panic(err) } - for i := 1; i < n; i++ { - connect(switches, 0, i) + for i := 0; i < n; i++ { + for j := i + 1; j < n; j++ { + connect(switches, i, j) + } } return switches diff --git a/p2p/switch_test.go b/p2p/switch_test.go index 115811b0..dd9e90a9 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -286,6 +286,21 @@ func TestSwitchReconnectsToPersistentPeer(t *testing.T) { assert.False(peer.IsRunning()) } +func TestSwitchFullConnectivity(t *testing.T) { + switches := MakeConnectedSwitches(config, 3, initSwitchFunc, Connect2Switches) + defer func() { + for _, sw := range switches { + sw.Stop() + } + }() + + for i, sw := range switches { + if sw.Peers().Size() != 2 { + t.Fatalf("Expected each switch to be connected to 2 other, but %d switch only connected to %d", sw.Peers().Size(), i) + } + } +} + func BenchmarkSwitches(b *testing.B) { b.StopTimer()