From a0dfb36342b9e7883b3ceec0d6a415ce346d9bb7 Mon Sep 17 00:00:00 2001 From: Janos Guljas Date: Wed, 12 Dec 2018 15:14:06 +0100 Subject: [PATCH] p2p/simulations: add "conns after load" subtest to TestSnapshot and nudge --- p2p/simulations/network_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/p2p/simulations/network_test.go b/p2p/simulations/network_test.go index 71594c5cb3..b7852addb9 100644 --- a/p2p/simulations/network_test.go +++ b/p2p/simulations/network_test.go @@ -245,6 +245,37 @@ OUTER_TWO: t.Fatalf("Superfluous conn found %v -> %v", ev.Conn.One, ev.Conn.Other) } } + + // This test validates if all connections from the snapshot + // are created in the network. + t.Run("conns after load", func(t *testing.T) { + // Create new network. + n := NewNetwork( + adapters.NewSimAdapter(adapters.Services{ + "noopwoop": func(ctx *adapters.ServiceContext) (node.Service, error) { + return NewNoopService(nil), nil + }, + }), + &NetworkConfig{ + DefaultService: "noopwoop", + }, + ) + defer n.Shutdown() + + // Load the same snapshot. + err := n.Load(snap) + if err != nil { + t.Fatal(err) + } + + // Check every connection from the snapshot + // if it is in the network, too. + for _, c := range snap.Conns { + if n.GetConn(c.One, c.Other) == nil { + t.Errorf("missing connection: %s -> %s", c.One, c.Other) + } + } + }) } // TestNetworkSimulation creates a multi-node simulation network with each node