Skip to content

Commit

Permalink
pythongh-122957: Fix test flakiness in asyncio test in free-thread bu…
Browse files Browse the repository at this point in the history
…ild (python#124039)
  • Loading branch information
lesteve authored Sep 13, 2024
1 parent 9f42b62 commit eadb966
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Lib/test/test_asyncio/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ async def test_to_thread_once(self):
func.assert_called_once()

async def test_to_thread_concurrent(self):
func = mock.Mock()
calls = []
def func():
calls.append(1)

futs = []
for _ in range(10):
fut = asyncio.to_thread(func)
futs.append(fut)
await asyncio.gather(*futs)

self.assertEqual(func.call_count, 10)
self.assertEqual(sum(calls), 10)

async def test_to_thread_args_kwargs(self):
# Unlike run_in_executor(), to_thread() should directly accept kwargs.
Expand Down

0 comments on commit eadb966

Please sign in to comment.