From 994d371ff1bd67a976c99c644f1e321672411c6d Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 14 Jan 2020 10:49:34 +0000 Subject: [PATCH] Removed redundant comments. Add proper PruneStalePeers test. --- network/node.go | 2 -- network/node_test.go | 21 +++++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/network/node.go b/network/node.go index a5d3ad91..caacc7fd 100644 --- a/network/node.go +++ b/network/node.go @@ -102,7 +102,6 @@ func (n *node) walk(until func(peer *node) bool, action func(parent, peer *node) for queue.Len() > 0 { // pop the node from the front of the queue qnode := queue.Front() - //fmt.Printf("qnodeValue: %v\n", qnode.Value.(*node)) if until(qnode.Value.(*node)) { return visited } @@ -112,7 +111,6 @@ func (n *node) walk(until func(peer *node) bool, action func(parent, peer *node) action(qnode.Value.(*node), peer) if _, ok := visited[id]; !ok { visited[id] = peer - //action(qnode.Value.(*node), peer) queue.PushBack(peer) } } diff --git a/network/node_test.go b/network/node_test.go index 7f2efe3b..fc3088df 100644 --- a/network/node_test.go +++ b/network/node_test.go @@ -233,9 +233,8 @@ func TestPrunePeer(t *testing.T) { func TestPruneStalePeers(t *testing.T) { // complicated node graph node := testSetup() - nodes := node.Nodes() - + // this will delete all nodes besides the root node pruneTime := 10 * time.Millisecond time.Sleep(pruneTime) @@ -245,6 +244,24 @@ func TestPruneStalePeers(t *testing.T) { if len(pruned) != len(nodes)-1 { t.Errorf("Expected pruned node count: %d, got: %d", len(nodes)-1, len(pruned)) } + + // complicated node graph + node = testSetup() + nodes = node.Nodes() + + // set prune time to 100ms and wait for half of it + pruneTime = 100 * time.Millisecond + time.Sleep(pruneTime) + + // update the time of peer1 + node.peers["peer1"].lastSeen = time.Now() + + // should prune all but the root nodes and peer1 + pruned = node.PruneStalePeers(pruneTime) + + if len(pruned) != len(nodes)-2 { + t.Errorf("Expected pruned node count: %d, got: %d", len(nodes)-2, len(pruned)) + } } func TestUnpackPeerTopology(t *testing.T) {