p2p/simulations: add more test cases for ConnectNodesFull()

As I surprised myself it works even with 0 or 1 nodes.
This commit is contained in:
Ferenc Szabo 2018-12-19 14:05:32 +01:00
parent 7240f4d800
commit 566901f92d

View file

@ -125,15 +125,30 @@ func TestConnectToRandomNode(t *testing.T) {
} }
func TestConnectNodesFull(t *testing.T) { func TestConnectNodesFull(t *testing.T) {
net, ids := newTestNetwork(t, 12) tests := []struct {
defer net.Shutdown() name string
nodeCount int
err := net.ConnectNodesFull(ids) }{
if err != nil { {name: "no node", nodeCount: 0},
t.Fatal(err) {name: "single node", nodeCount: 1},
{name: "2 nodes", nodeCount: 2},
{name: "3 nodes", nodeCount: 3},
{name: "even number of nodes", nodeCount: 12},
{name: "odd number of nodes", nodeCount: 13},
} }
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
net, ids := newTestNetwork(t, test.nodeCount)
defer net.Shutdown()
VerifyFull(t, net, ids) err := net.ConnectNodesFull(ids)
if err != nil {
t.Fatal(err)
}
VerifyFull(t, net, ids)
})
}
} }
func TestConnectNodesChain(t *testing.T) { func TestConnectNodesChain(t *testing.T) {