From 2d515c84acef39e9642358f442575bdc2d04c8de Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 26 Jan 2025 18:35:10 +0100 Subject: [PATCH] Increase test timing to reduce flakiness. --- tests/asyncio/test_connection.py | 14 +++++++------- tests/sync/test_connection.py | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/asyncio/test_connection.py b/tests/asyncio/test_connection.py index dc453994..5230eca8 100644 --- a/tests/asyncio/test_connection.py +++ b/tests/asyncio/test_connection.py @@ -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) @@ -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): diff --git a/tests/sync/test_connection.py b/tests/sync/test_connection.py index be7ff36f..a5aee35b 100644 --- a/tests/sync/test_connection.py +++ b/tests/sync/test_connection.py @@ -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) @@ -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):