From 1628c52558aa51ef3a6386f72001102e9de3a61d Mon Sep 17 00:00:00 2001 From: Mark Vujevits Date: Wed, 7 Nov 2018 14:23:55 +0100 Subject: [PATCH] add assertions to check peers in live connections --- swarm/network/kademlia_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/swarm/network/kademlia_test.go b/swarm/network/kademlia_test.go index f5d87fee85..d2e051f457 100644 --- a/swarm/network/kademlia_test.go +++ b/swarm/network/kademlia_test.go @@ -263,12 +263,20 @@ func TestOffEffectingAddressBookNormalNode(t *testing.T) { if k.addrs.Size() != 1 { t.Fatal("known peer addresses should contain 1 entry") } + // peer should be among live connections + if k.conns.Size() != 1 { + t.Fatal("live peers should contain 1 entry") + } // remove peer from kademlia k.Off(newTestKadPeer(k, "01000000", false)) - // peer should not be in the address book + // peer should be in the address book if k.addrs.Size() != 1 { t.Fatal("known peer addresses should contain 1 entry") } + // peer should not be among live connections + if k.conns.Size() != 0 { + t.Fatal("live peers should contain 0 entry") + } } // a light node should not be in the address book @@ -280,12 +288,20 @@ func TestOffEffectingAddressBookLightNode(t *testing.T) { if k.addrs.Size() != 0 { t.Fatal("known peer addresses should contain 0 entry") } + // peer should be among live connections + if k.conns.Size() != 1 { + t.Fatal("live peers should contain 1 entry") + } // remove peer from kademlia k.Off(newTestKadPeer(k, "01000000", true)) // peer should not be in the address book if k.addrs.Size() != 0 { t.Fatal("known peer addresses should contain 0 entry") } + // peer should not be among live connections + if k.conns.Size() != 0 { + t.Fatal("live peers should contain 0 entry") + } } func TestSuggestPeerRetries(t *testing.T) {