Skip to content

Commit 2d515c8

Browse files
committed
Increase test timing to reduce flakiness.
1 parent dfea9b3 commit 2d515c8

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

tests/asyncio/test_connection.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -980,13 +980,14 @@ async def test_pong_unsupported_type(self):
980980
@patch("random.getrandbits", return_value=1918987876)
981981
async def test_keepalive(self, getrandbits):
982982
"""keepalive sends pings at ping_interval and measures latency."""
983-
self.connection.ping_interval = 2 * MS
983+
self.connection.ping_interval = 3 * MS
984984
self.connection.start_keepalive()
985+
self.assertIsNotNone(self.connection.keepalive_task)
985986
self.assertEqual(self.connection.latency, 0)
986-
# 2 ms: keepalive() sends a ping frame.
987-
# 2.x ms: a pong frame is received.
988-
await asyncio.sleep(3 * MS)
989-
# 3 ms: check that the ping frame was sent.
987+
# 3 ms: keepalive() sends a ping frame.
988+
# 3.x ms: a pong frame is received.
989+
await asyncio.sleep(4 * MS)
990+
# 4 ms: check that the ping frame was sent.
990991
await self.assertFrameSent(Frame(Opcode.PING, b"rand"))
991992
self.assertGreater(self.connection.latency, 0)
992993
self.assertLess(self.connection.latency, MS)
@@ -995,8 +996,7 @@ async def test_disable_keepalive(self):
995996
"""keepalive is disabled when ping_interval is None."""
996997
self.connection.ping_interval = None
997998
self.connection.start_keepalive()
998-
await asyncio.sleep(3 * MS)
999-
await self.assertNoFrameSent()
999+
self.assertIsNone(self.connection.keepalive_task)
10001000

10011001
@patch("random.getrandbits", return_value=1918987876)
10021002
async def test_keepalive_times_out(self, getrandbits):

tests/sync/test_connection.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -742,13 +742,14 @@ def test_pong_unsupported_type(self):
742742
@patch("random.getrandbits", return_value=1918987876)
743743
def test_keepalive(self, getrandbits):
744744
"""keepalive sends pings at ping_interval and measures latency."""
745-
self.connection.ping_interval = 2 * MS
745+
self.connection.ping_interval = 4 * MS
746746
self.connection.start_keepalive()
747+
self.assertIsNotNone(self.connection.keepalive_thread)
747748
self.assertEqual(self.connection.latency, 0)
748-
# 2 ms: keepalive() sends a ping frame.
749-
# 2.x ms: a pong frame is received.
750-
time.sleep(3 * MS)
751-
# 3 ms: check that the ping frame was sent.
749+
# 3 ms: keepalive() sends a ping frame.
750+
# 3.x ms: a pong frame is received.
751+
time.sleep(4 * MS)
752+
# 4 ms: check that the ping frame was sent.
752753
self.assertFrameSent(Frame(Opcode.PING, b"rand"))
753754
self.assertGreater(self.connection.latency, 0)
754755
self.assertLess(self.connection.latency, MS)
@@ -757,8 +758,7 @@ def test_disable_keepalive(self):
757758
"""keepalive is disabled when ping_interval is None."""
758759
self.connection.ping_interval = None
759760
self.connection.start_keepalive()
760-
time.sleep(3 * MS)
761-
self.assertNoFrameSent()
761+
self.assertIsNone(self.connection.keepalive_thread)
762762

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

0 commit comments

Comments
 (0)