Skip to content

Commit 4c1e99b

Browse files
committed
feat(test): Add flush to async transport test
Add flush to async transport test matrix. Additionally, explicitly shut down the worker task upon flushing in the tests, to avoid event loop errors. GH-4601
1 parent 76aae83 commit 4c1e99b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tests/test_transport.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_transport_works(
151151

152152
@pytest.mark.asyncio
153153
@pytest.mark.parametrize("debug", (True, False))
154-
@pytest.mark.parametrize("client_flush_method", ["close"])
154+
@pytest.mark.parametrize("client_flush_method", ["close", "flush"])
155155
@pytest.mark.parametrize("use_pickle", (True, False))
156156
@pytest.mark.parametrize("compression_level", (0, 9, None))
157157
@pytest.mark.parametrize("compression_algo", ("gzip", "br", "<invalid>", None))
@@ -203,6 +203,8 @@ async def test_transport_works_async(
203203

204204
if client_flush_method == "close":
205205
await client.close(timeout=2.0)
206+
if client_flush_method == "flush":
207+
await client.flush(timeout=2.0)
206208

207209
out, err = capsys.readouterr()
208210
assert not err and not out
@@ -222,8 +224,11 @@ async def test_transport_works_async(
222224
)
223225

224226
assert capturing_server.captured[0].compressed == should_compress
225-
227+
# After flush, the worker task is still running, but the end of the test will shut down the event loop
228+
# Therefore, we need to explicitly close the client to clean up the worker task
226229
assert any("Sending envelope" in record.msg for record in caplog.records) == debug
230+
if client_flush_method == "flush":
231+
await client.close(timeout=2.0)
227232

228233

229234
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)