gh-122957: Fix test flakiness in asyncio test in free-thread build (#124039)

This commit is contained in:
Loïc Estève 2024-09-13 20:13:30 +02:00 committed by GitHub
parent 9f42b62db9
commit eadb9660ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 2 deletions

View File

@ -30,7 +30,9 @@ class ToThreadTests(unittest.IsolatedAsyncioTestCase):
func.assert_called_once() func.assert_called_once()
async def test_to_thread_concurrent(self): async def test_to_thread_concurrent(self):
func = mock.Mock() calls = []
def func():
calls.append(1)
futs = [] futs = []
for _ in range(10): for _ in range(10):
@ -38,7 +40,7 @@ class ToThreadTests(unittest.IsolatedAsyncioTestCase):
futs.append(fut) futs.append(fut)
await asyncio.gather(*futs) await asyncio.gather(*futs)
self.assertEqual(func.call_count, 10) self.assertEqual(sum(calls), 10)
async def test_to_thread_args_kwargs(self): async def test_to_thread_args_kwargs(self):
# Unlike run_in_executor(), to_thread() should directly accept kwargs. # Unlike run_in_executor(), to_thread() should directly accept kwargs.