11import contextlib
2+ import itertools
23import logging
34import socket
45import sys
@@ -643,9 +644,10 @@ def fragments():
643644
644645 # Test ping.
645646
646- @patch ("random.getrandbits" , return_value = 1918987876 )
647+ @patch ("random.getrandbits" )
647648 def test_ping (self , getrandbits ):
648649 """ping sends a ping frame with a random payload."""
650+ getrandbits .side_effect = itertools .count (1918987876 )
649651 self .connection .ping ()
650652 getrandbits .assert_called_once_with (32 )
651653 self .assertFrameSent (Frame (Opcode .PING , b"rand" ))
@@ -737,10 +739,11 @@ def test_pong_unsupported_type(self):
737739
738740 # Test keepalive.
739741
740- @patch ("random.getrandbits" , return_value = 1918987876 )
742+ @patch ("random.getrandbits" )
741743 def test_keepalive (self , getrandbits ):
742744 """keepalive sends pings at ping_interval and measures latency."""
743745 self .connection .ping_interval = 4 * MS
746+ getrandbits .side_effect = itertools .count (1918987876 )
744747 self .connection .start_keepalive ()
745748 self .assertIsNotNone (self .connection .keepalive_thread )
746749 self .assertEqual (self .connection .latency , 0 )
@@ -758,9 +761,10 @@ def test_disable_keepalive(self):
758761 self .connection .start_keepalive ()
759762 self .assertIsNone (self .connection .keepalive_thread )
760763
761- @patch ("random.getrandbits" , return_value = 1918987876 )
764+ @patch ("random.getrandbits" )
762765 def test_keepalive_times_out (self , getrandbits ):
763766 """keepalive closes the connection if ping_timeout elapses."""
767+ getrandbits .side_effect = itertools .count (1918987876 )
764768 self .connection .ping_interval = 4 * MS
765769 self .connection .ping_timeout = 2 * MS
766770 with self .drop_frames_rcvd ():
@@ -774,9 +778,10 @@ def test_keepalive_times_out(self, getrandbits):
774778 # 7 ms: check that the connection is closed.
775779 self .assertEqual (self .connection .state , State .CLOSED )
776780
777- @patch ("random.getrandbits" , return_value = 1918987876 )
781+ @patch ("random.getrandbits" )
778782 def test_keepalive_ignores_timeout (self , getrandbits ):
779783 """keepalive ignores timeouts if ping_timeout isn't set."""
784+ getrandbits .side_effect = itertools .count (1918987876 )
780785 self .connection .ping_interval = 4 * MS
781786 self .connection .ping_timeout = None
782787 with self .drop_frames_rcvd ():
0 commit comments