Skip to content

Commit f075aac

Browse files
committed
Restore semantics of tests.
They relied (accidentally) on wait_for() creating a task, causing the event loop to run once when calling close().
1 parent 808d854 commit f075aac

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tests/legacy/test_protocol.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ def half_close_connection_local(self, code=1000, reason="close"):
190190
close_frame_data = Close(code, reason).serialize()
191191
# Trigger the closing handshake from the local endpoint.
192192
close_task = self.loop.create_task(self.protocol.close(code, reason))
193-
self.run_loop_once() # wait_for executes
194193
self.run_loop_once() # write_frame executes
195194
# Empty the outgoing data stream so we can make assertions later on.
196195
self.assertOneFrameSent(True, OP_CLOSE, close_frame_data)
@@ -919,6 +918,7 @@ def test_answer_ping_does_not_crash_if_connection_closing(self):
919918
close_task = self.half_close_connection_local()
920919

921920
self.receive_frame(Frame(True, OP_PING, b"test"))
921+
self.run_loop_once()
922922

923923
with self.assertNoLogs():
924924
self.loop.run_until_complete(self.protocol.close())
@@ -931,6 +931,7 @@ def test_answer_ping_does_not_crash_if_connection_closed(self):
931931
# which prevents responding with a pong frame properly.
932932
self.receive_frame(Frame(True, OP_PING, b"test"))
933933
self.receive_eof()
934+
self.run_loop_once()
934935

935936
with self.assertNoLogs():
936937
self.loop.run_until_complete(self.protocol.close())
@@ -1362,6 +1363,7 @@ def test_remote_close_and_connection_lost(self):
13621363
# which prevents echoing the close frame properly.
13631364
self.receive_frame(self.close_frame)
13641365
self.receive_eof()
1366+
self.run_loop_once()
13651367

13661368
with self.assertNoLogs():
13671369
self.loop.run_until_complete(self.protocol.close(reason="oh noes!"))
@@ -1375,6 +1377,7 @@ def test_simultaneous_close(self):
13751377
# https://github.com/aaugustin/websockets/issues/339
13761378
self.loop.call_soon(self.receive_frame, self.remote_close)
13771379
self.loop.call_soon(self.receive_eof_if_client)
1380+
self.run_loop_once()
13781381

13791382
self.loop.run_until_complete(self.protocol.close(reason="local"))
13801383

@@ -1386,6 +1389,7 @@ def test_simultaneous_close(self):
13861389

13871390
def test_close_preserves_incoming_frames(self):
13881391
self.receive_frame(Frame(True, OP_TEXT, b"hello"))
1392+
self.run_loop_once()
13891393

13901394
self.loop.call_later(MS, self.receive_frame, self.close_frame)
13911395
self.loop.call_later(MS, self.receive_eof_if_client)
@@ -1573,6 +1577,7 @@ def test_local_close_connection_lost_timeout_after_write_eof(self):
15731577
# HACK: disable write_eof => other end drops connection emulation.
15741578
self.transport._eof = True
15751579
self.receive_frame(self.close_frame)
1580+
self.run_loop_once()
15761581
self.loop.run_until_complete(self.protocol.close(reason="close"))
15771582
self.assertConnectionClosed(1000, "close")
15781583

@@ -1589,6 +1594,7 @@ def test_local_close_connection_lost_timeout_after_close(self):
15891594
# HACK: disable close => other end drops connection emulation.
15901595
self.transport._closing = True
15911596
self.receive_frame(self.close_frame)
1597+
self.run_loop_once()
15921598
self.loop.run_until_complete(self.protocol.close(reason="close"))
15931599
self.assertConnectionClosed(1000, "close")
15941600

@@ -1631,6 +1637,7 @@ def test_local_close_connection_lost_timeout_after_write_eof(self):
16311637
# HACK: disable write_eof => other end drops connection emulation.
16321638
self.transport._eof = True
16331639
self.receive_frame(self.close_frame)
1640+
self.run_loop_once()
16341641
self.loop.run_until_complete(self.protocol.close(reason="close"))
16351642
self.assertConnectionClosed(1000, "close")
16361643

@@ -1650,5 +1657,6 @@ def test_local_close_connection_lost_timeout_after_close(self):
16501657
# HACK: disable close => other end drops connection emulation.
16511658
self.transport._closing = True
16521659
self.receive_frame(self.close_frame)
1660+
self.run_loop_once()
16531661
self.loop.run_until_complete(self.protocol.close(reason="close"))
16541662
self.assertConnectionClosed(1000, "close")

0 commit comments

Comments
 (0)