diff --git a/p2p/switch.go b/p2p/switch.go index 994a3344..62f44d8f 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -499,7 +499,7 @@ func MakeConnectedSwitches(cfg *cfg.P2PConfig, n int, initSwitch func(int, *Swit } for i := 0; i < n; i++ { - for j := i; j < n; j++ { + for j := i + 1; j < n; j++ { connect(switches, i, j) } } diff --git a/p2p/switch_test.go b/p2p/switch_test.go index 2a42b844..d7443e94 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -268,6 +268,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()