Removed redundant comments. Add proper PruneStalePeers test.

This commit is contained in:
Milos Gajdos 2020-01-14 10:49:34 +00:00
parent a91dad04ee
commit 994d371ff1
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F
2 changed files with 19 additions and 4 deletions

View File

@ -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)
}
}

View File

@ -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) {