@@ -104,32 +104,18 @@ def test_getpeerinfo(self):
104104
105105 def test_getnettotals (self ):
106106 self .log .info ("Test getnettotals" )
107- # getnettotals totalbytesrecv and totalbytessent should be
108- # consistent with getpeerinfo. Since the RPC calls are not atomic,
109- # and messages might have been recvd or sent between RPC calls, call
110- # getnettotals before and after and verify that the returned values
111- # from getpeerinfo are bounded by those values.
107+ # Test getnettotals and getpeerinfo by doing a ping. The bytes
108+ # sent/received should increase by at least the size of one ping (32
109+ # bytes) and one pong (32 bytes).
112110 net_totals_before = self .nodes [0 ].getnettotals ()
113- peer_info = self .nodes [0 ].getpeerinfo ()
114- net_totals_after = self .nodes [0 ].getnettotals ()
115- assert_equal (len (peer_info ), 2 )
116- peers_recv = sum ([peer ['bytesrecv' ] for peer in peer_info ])
117- peers_sent = sum ([peer ['bytessent' ] for peer in peer_info ])
118-
119- assert_greater_than_or_equal (peers_recv , net_totals_before ['totalbytesrecv' ])
120- assert_greater_than_or_equal (net_totals_after ['totalbytesrecv' ], peers_recv )
121- assert_greater_than_or_equal (peers_sent , net_totals_before ['totalbytessent' ])
122- assert_greater_than_or_equal (net_totals_after ['totalbytessent' ], peers_sent )
123-
124- # test getnettotals and getpeerinfo by doing a ping
125- # the bytes sent/received should change
126- # note ping and pong are 32 bytes each
111+ peer_info_before = self .nodes [0 ].getpeerinfo ()
112+
127113 self .nodes [0 ].ping ()
128- self .wait_until (lambda : (self .nodes [0 ].getnettotals ()['totalbytessent' ] >= net_totals_after ['totalbytessent' ] + 32 * 2 ), timeout = 1 )
129- self .wait_until (lambda : (self .nodes [0 ].getnettotals ()['totalbytesrecv' ] >= net_totals_after ['totalbytesrecv' ] + 32 * 2 ), timeout = 1 )
114+ self .wait_until (lambda : (self .nodes [0 ].getnettotals ()['totalbytessent' ] >= net_totals_before ['totalbytessent' ] + 32 * 2 ), timeout = 1 )
115+ self .wait_until (lambda : (self .nodes [0 ].getnettotals ()['totalbytesrecv' ] >= net_totals_before ['totalbytesrecv' ] + 32 * 2 ), timeout = 1 )
130116
131- peer_info_after_ping = self .nodes [0 ].getpeerinfo ()
132- for before , after in zip (peer_info , peer_info_after_ping ):
117+ peer_info_after = self .nodes [0 ].getpeerinfo ()
118+ for before , after in zip (peer_info_before , peer_info_after ):
133119 assert_greater_than_or_equal (after ['bytesrecv_per_msg' ].get ('pong' , 0 ), before ['bytesrecv_per_msg' ].get ('pong' , 0 ) + 32 )
134120 assert_greater_than_or_equal (after ['bytessent_per_msg' ].get ('ping' , 0 ), before ['bytessent_per_msg' ].get ('ping' , 0 ) + 32 )
135121
0 commit comments