Skip to content

Commit

Permalink
Work around bug in coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Apr 2, 2023
1 parent f075aac commit 901e434
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/websockets/legacy/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,8 @@ async def close_transport(self) -> None:
# Abort the TCP connection. Buffers are discarded.
if self.debug:
self.logger.debug("x aborting TCP connection")
self.transport.abort()
# Due to a bug in coverage, this is erroneously reported as not covered.
self.transport.abort() # pragma: no cover

# connection_lost() is called quickly after aborting.
await self.wait_for_connection_lost()
Expand Down
18 changes: 12 additions & 6 deletions tests/legacy/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,8 @@ def test_local_close_connection_lost_timeout_after_write_eof(self):
self.receive_frame(self.close_frame)
self.run_loop_once()
self.loop.run_until_complete(self.protocol.close(reason="close"))
self.assertConnectionClosed(1000, "close")
# Due to a bug in coverage, this is erroneously reported as not covered.
self.assertConnectionClosed(1000, "close") # pragma: no cover

def test_local_close_connection_lost_timeout_after_close(self):
self.protocol.close_timeout = 10 * MS
Expand All @@ -1596,7 +1597,8 @@ def test_local_close_connection_lost_timeout_after_close(self):
self.receive_frame(self.close_frame)
self.run_loop_once()
self.loop.run_until_complete(self.protocol.close(reason="close"))
self.assertConnectionClosed(1000, "close")
# Due to a bug in coverage, this is erroneously reported as not covered.
self.assertConnectionClosed(1000, "close") # pragma: no cover


class ClientTests(CommonTests, AsyncioTestCase):
Expand All @@ -1614,7 +1616,8 @@ def test_local_close_send_close_frame_timeout(self):
# Check the timing within -1/+9ms for robustness.
with self.assertCompletesWithin(19 * MS, 29 * MS):
self.loop.run_until_complete(self.protocol.close(reason="close"))
self.assertConnectionClosed(1006, "")
# Due to a bug in coverage, this is erroneously reported as not covered.
self.assertConnectionClosed(1006, "") # pragma: no cover

def test_local_close_receive_close_frame_timeout(self):
self.protocol.close_timeout = 10 * MS
Expand All @@ -1624,7 +1627,8 @@ def test_local_close_receive_close_frame_timeout(self):
# Check the timing within -1/+9ms for robustness.
with self.assertCompletesWithin(19 * MS, 29 * MS):
self.loop.run_until_complete(self.protocol.close(reason="close"))
self.assertConnectionClosed(1006, "")
# Due to a bug in coverage, this is erroneously reported as not covered.
self.assertConnectionClosed(1006, "") # pragma: no cover

def test_local_close_connection_lost_timeout_after_write_eof(self):
self.protocol.close_timeout = 10 * MS
Expand All @@ -1639,7 +1643,8 @@ def test_local_close_connection_lost_timeout_after_write_eof(self):
self.receive_frame(self.close_frame)
self.run_loop_once()
self.loop.run_until_complete(self.protocol.close(reason="close"))
self.assertConnectionClosed(1000, "close")
# Due to a bug in coverage, this is erroneously reported as not covered.
self.assertConnectionClosed(1000, "close") # pragma: no cover

def test_local_close_connection_lost_timeout_after_close(self):
self.protocol.close_timeout = 10 * MS
Expand All @@ -1659,4 +1664,5 @@ def test_local_close_connection_lost_timeout_after_close(self):
self.receive_frame(self.close_frame)
self.run_loop_once()
self.loop.run_until_complete(self.protocol.close(reason="close"))
self.assertConnectionClosed(1000, "close")
# Due to a bug in coverage, this is erroneously reported as not covered.
self.assertConnectionClosed(1000, "close") # pragma: no cover

0 comments on commit 901e434

Please sign in to comment.