Skip to content

Commit

Permalink
fix test_concurrency socket unclosed
Browse files Browse the repository at this point in the history
  • Loading branch information
euri10 committed Nov 29, 2024
1 parent 3f8c8b9 commit 70f2250
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/unit/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_get_set_asyncio_executor() -> None:
executor = ThreadPoolExecutor()
set_asyncio_executor(executor)
assert get_asyncio_executor() is executor
executor.shutdown(False)


def test_get_set_trio_capacity_limiter() -> None:
Expand All @@ -68,14 +69,17 @@ def test_asyncio_uses_executor(mocker: MockerFixture) -> None:
loop.close()

assert mock_run_in_executor.call_args_list[0].args[0] is executor
executor.shutdown(False)


def test_set_asyncio_executor_from_running_loop_raises() -> None:
async def main() -> None:
set_asyncio_executor(ThreadPoolExecutor())

with pytest.raises(RuntimeError):
asyncio.new_event_loop().run_until_complete(main())
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.close()

assert get_asyncio_executor() is None

Expand Down Expand Up @@ -104,4 +108,6 @@ def test_sync_to_thread_unsupported_lib(mocker: MockerFixture) -> None:
mocker.patch("litestar.concurrency.sniffio.current_async_library", return_value="something")

with pytest.raises(RuntimeError):
asyncio.new_event_loop().run_until_complete(sync_to_thread(func))
loop = asyncio.new_event_loop()
loop.run_until_complete(sync_to_thread(func))
loop.close()

0 comments on commit 70f2250

Please sign in to comment.