Skip to content

Commit

Permalink
more debug
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Jan 26, 2025
1 parent 08ac8cd commit 2e3d913
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 12 additions & 4 deletions tests/asyncio/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def create_connection(*args, **kwargs):
) as client:
self.assertTrue(client.create_connection_ran)

@unittest.skip("TODO - skipped to get a passing run")
async def test_reconnect(self):
"""Client reconnects to server."""
iterations = 0
Expand All @@ -165,16 +164,24 @@ async def test_reconnect(self):
async def process_request(connection, request):
nonlocal iterations
iterations += 1
connection.logger.critical(f"!!!!! ITERATION {iterations}")
# Retriable errors
if iterations == 1:
await asyncio.sleep(3 * MS)
elif iterations == 2:
connection.transport.close()
elif iterations == 3:
return connection.respond(http.HTTPStatus.SERVICE_UNAVAILABLE, "🚒")
# Successful connection
elif iterations == 4:
pass
elif iterations == 5:
pass
# Fatal error
elif iterations == 6:
return connection.respond(http.HTTPStatus.PAYMENT_REQUIRED, "💸")
else:
self.fail("should stop after 6 iterations")

async with serve(*args, process_request=process_request) as server:
with self.assertRaises(InvalidStatus) as raised:
Expand All @@ -190,7 +197,6 @@ async def process_request(connection, request):
self.assertEqual(iterations, 6)
self.assertEqual(successful, 2)

@unittest.skip("TODO - skipped to get a passing run")
async def test_reconnect_with_custom_process_exception(self):
"""Client runs process_exception to tell if errors are retryable or fatal."""
iteration = 0
Expand All @@ -200,7 +206,10 @@ def process_request(connection, request):
iteration += 1
if iteration == 1:
return connection.respond(http.HTTPStatus.SERVICE_UNAVAILABLE, "🚒")
return connection.respond(http.HTTPStatus.IM_A_TEAPOT, "🫖")
elif iteration == 2:
return connection.respond(http.HTTPStatus.IM_A_TEAPOT, "🫖")
else:
self.fail("should stop after 2 iterations")

def process_exception(exc):
if isinstance(exc, InvalidStatus):
Expand All @@ -224,7 +233,6 @@ def process_exception(exc):
"🫖 💔 ☕️",
)

@unittest.skip("TODO - skipped to get a passing run")
async def test_reconnect_with_custom_process_exception_raising_exception(self):
"""Client supports raising an exception in process_exception."""

Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ deps =

[testenv:coverage]
commands =
python -m coverage run --source {envsitepackagesdir}/websockets,tests -m unittest {posargs}
python -u -m coverage run --source {envsitepackagesdir}/websockets,tests -m unittest -v -k test_reconnect {posargs}
python -m coverage report --show-missing --fail-under=100
deps =
coverage
mitmproxy
python-socks
setenv =
WEBSOCKETS_DEBUG=1

[testenv:maxi_cov]
commands =
Expand Down

0 comments on commit 2e3d913

Please sign in to comment.