Skip to content

Commit

Permalink
Increase test timing to reduce flakiness.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Jan 26, 2025
1 parent dfea9b3 commit 2d515c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions tests/asyncio/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,13 +980,14 @@ async def test_pong_unsupported_type(self):
@patch("random.getrandbits", return_value=1918987876)
async def test_keepalive(self, getrandbits):
"""keepalive sends pings at ping_interval and measures latency."""
self.connection.ping_interval = 2 * MS
self.connection.ping_interval = 3 * MS
self.connection.start_keepalive()
self.assertIsNotNone(self.connection.keepalive_task)
self.assertEqual(self.connection.latency, 0)
# 2 ms: keepalive() sends a ping frame.
# 2.x ms: a pong frame is received.
await asyncio.sleep(3 * MS)
# 3 ms: check that the ping frame was sent.
# 3 ms: keepalive() sends a ping frame.
# 3.x ms: a pong frame is received.
await asyncio.sleep(4 * MS)
# 4 ms: check that the ping frame was sent.
await self.assertFrameSent(Frame(Opcode.PING, b"rand"))
self.assertGreater(self.connection.latency, 0)
self.assertLess(self.connection.latency, MS)
Expand All @@ -995,8 +996,7 @@ async def test_disable_keepalive(self):
"""keepalive is disabled when ping_interval is None."""
self.connection.ping_interval = None
self.connection.start_keepalive()
await asyncio.sleep(3 * MS)
await self.assertNoFrameSent()
self.assertIsNone(self.connection.keepalive_task)

@patch("random.getrandbits", return_value=1918987876)
async def test_keepalive_times_out(self, getrandbits):
Expand Down
14 changes: 7 additions & 7 deletions tests/sync/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,13 +742,14 @@ def test_pong_unsupported_type(self):
@patch("random.getrandbits", return_value=1918987876)
def test_keepalive(self, getrandbits):
"""keepalive sends pings at ping_interval and measures latency."""
self.connection.ping_interval = 2 * MS
self.connection.ping_interval = 4 * MS
self.connection.start_keepalive()
self.assertIsNotNone(self.connection.keepalive_thread)
self.assertEqual(self.connection.latency, 0)
# 2 ms: keepalive() sends a ping frame.
# 2.x ms: a pong frame is received.
time.sleep(3 * MS)
# 3 ms: check that the ping frame was sent.
# 3 ms: keepalive() sends a ping frame.
# 3.x ms: a pong frame is received.
time.sleep(4 * MS)
# 4 ms: check that the ping frame was sent.
self.assertFrameSent(Frame(Opcode.PING, b"rand"))
self.assertGreater(self.connection.latency, 0)
self.assertLess(self.connection.latency, MS)
Expand All @@ -757,8 +758,7 @@ def test_disable_keepalive(self):
"""keepalive is disabled when ping_interval is None."""
self.connection.ping_interval = None
self.connection.start_keepalive()
time.sleep(3 * MS)
self.assertNoFrameSent()
self.assertIsNone(self.connection.keepalive_thread)

@patch("random.getrandbits", return_value=1918987876)
def test_keepalive_times_out(self, getrandbits):
Expand Down

0 comments on commit 2d515c8

Please sign in to comment.