Skip to content

Commit 492d22f

Browse files
author
MarcoFalke
committed
Merge #10264: [test] Add tests for getconnectioncount, getnettotals and ping
85f950a [test] Add tests for getconnectioncount, getnettotals and ping (Jimmy Song) Tree-SHA512: f9cccc749cd897a4e90400173d63da27798fe606ede216bdcfcce73848370327e010fa7ae70bd2974b24b3e688337e2ad18f0959ffed57cae9c0803456bab09a
2 parents 9c33ffd + 85f950a commit 492d22f

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

test/functional/net.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,39 @@ def setup_network(self):
3232
self.sync_all()
3333

3434
def run_test(self):
35+
self._test_connection_count()
36+
self._test_getnettotals()
37+
self._test_getnetworkinginfo()
38+
self._test_getaddednodeinfo()
39+
40+
def _test_connection_count(self):
41+
# connect_nodes_bi connects each node to the other
42+
assert_equal(self.nodes[0].getconnectioncount(), 2)
43+
44+
def _test_getnettotals(self):
45+
# check that getnettotals totalbytesrecv and totalbytessent
46+
# are consistent with getpeerinfo
47+
peer_info = self.nodes[0].getpeerinfo()
48+
assert_equal(len(peer_info), 2)
49+
net_totals = self.nodes[0].getnettotals()
50+
assert_equal(sum([peer['bytesrecv'] for peer in peer_info]),
51+
net_totals['totalbytesrecv'])
52+
assert_equal(sum([peer['bytessent'] for peer in peer_info]),
53+
net_totals['totalbytessent'])
54+
# test getnettotals and getpeerinfo by doing a ping
55+
# the bytes sent/received should change
56+
# note ping and pong are 32 bytes each
57+
self.nodes[0].ping()
58+
time.sleep(0.1)
59+
peer_info_after_ping = self.nodes[0].getpeerinfo()
60+
net_totals_after_ping = self.nodes[0].getnettotals()
61+
for before, after in zip(peer_info, peer_info_after_ping):
62+
assert_equal(before['bytesrecv_per_msg']['pong'] + 32, after['bytesrecv_per_msg']['pong'])
63+
assert_equal(before['bytessent_per_msg']['ping'] + 32, after['bytessent_per_msg']['ping'])
64+
assert_equal(net_totals['totalbytesrecv'] + 32*2, net_totals_after_ping['totalbytesrecv'])
65+
assert_equal(net_totals['totalbytessent'] + 32*2, net_totals_after_ping['totalbytessent'])
66+
67+
def _test_getnetworkinginfo(self):
3568
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
3669
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
3770

@@ -49,7 +82,7 @@ def run_test(self):
4982
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
5083
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
5184

52-
# test getaddednodeinfo
85+
def _test_getaddednodeinfo(self):
5386
assert_equal(self.nodes[0].getaddednodeinfo(), [])
5487
# add a node (node2) to node0
5588
ip_port = "127.0.0.1:{}".format(p2p_port(2))

0 commit comments

Comments
 (0)