11import asyncio
22import contextlib
3+ import itertools
34import logging
45import socket
56import sys
@@ -903,9 +904,10 @@ async def test_wait_closed(self):
903904
904905 # Test ping.
905906
906- @patch ("random.getrandbits" , return_value = 1918987876 )
907+ @patch ("random.getrandbits" )
907908 async def test_ping (self , getrandbits ):
908909 """ping sends a ping frame with a random payload."""
910+ getrandbits .side_effect = itertools .count (1918987876 )
909911 await self .connection .ping ()
910912 getrandbits .assert_called_once_with (32 )
911913 await self .assertFrameSent (Frame (Opcode .PING , b"rand" ))
@@ -1014,9 +1016,10 @@ async def test_pong_unsupported_type(self):
10141016
10151017 # Test keepalive.
10161018
1017- @patch ("random.getrandbits" , return_value = 1918987876 )
1019+ @patch ("random.getrandbits" )
10181020 async def test_keepalive (self , getrandbits ):
10191021 """keepalive sends pings at ping_interval and measures latency."""
1022+ getrandbits .side_effect = itertools .count (1918987876 )
10201023 self .connection .ping_interval = 3 * MS
10211024 self .connection .start_keepalive ()
10221025 self .assertIsNotNone (self .connection .keepalive_task )
@@ -1035,9 +1038,10 @@ async def test_disable_keepalive(self):
10351038 self .connection .start_keepalive ()
10361039 self .assertIsNone (self .connection .keepalive_task )
10371040
1038- @patch ("random.getrandbits" , return_value = 1918987876 )
1041+ @patch ("random.getrandbits" )
10391042 async def test_keepalive_times_out (self , getrandbits ):
10401043 """keepalive closes the connection if ping_timeout elapses."""
1044+ getrandbits .side_effect = itertools .count (1918987876 )
10411045 self .connection .ping_interval = 4 * MS
10421046 self .connection .ping_timeout = 2 * MS
10431047 async with self .drop_frames_rcvd ():
@@ -1050,9 +1054,10 @@ async def test_keepalive_times_out(self, getrandbits):
10501054 # 7 ms: check that the connection is closed.
10511055 self .assertEqual (self .connection .state , State .CLOSED )
10521056
1053- @patch ("random.getrandbits" , return_value = 1918987876 )
1057+ @patch ("random.getrandbits" )
10541058 async def test_keepalive_ignores_timeout (self , getrandbits ):
10551059 """keepalive ignores timeouts if ping_timeout isn't set."""
1060+ getrandbits .side_effect = itertools .count (1918987876 )
10561061 self .connection .ping_interval = 4 * MS
10571062 self .connection .ping_timeout = None
10581063 async with self .drop_frames_rcvd ():
0 commit comments