Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 07e50c6

Browse filesBrowse files
committed
gh-91048: Fix race in test_async_global_awaited_by
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
1 parent 1d9406e commit 07e50c6
Copy full SHA for 07e50c6

File tree

Expand file treeCollapse file tree

1 file changed

+11
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-6
lines changed

‎Lib/test/test_external_inspection.py

Copy file name to clipboardExpand all lines: Lib/test/test_external_inspection.py
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
import socket
77
from unittest.mock import ANY
8-
from test.support import os_helper, SHORT_TIMEOUT, busy_retry, requires_gil_enabled
8+
from test.support import os_helper, SHORT_TIMEOUT, busy_retry
99
from test.support.script_helper import make_script
1010
from test.support.socket_helper import find_unused_port
1111

@@ -406,7 +406,6 @@ async def main():
406406
self.assertEqual(stack_trace, expected_stack_trace)
407407

408408
@skip_if_not_supported
409-
@requires_gil_enabled("gh-133359: occasionally flaky on AMD64")
410409
@unittest.skipIf(sys.platform == "linux" and not PROCESS_VM_READV_SUPPORTED,
411410
"Test only runs on Linux with process_vm_readv support")
412411
def test_async_global_awaited_by(self):
@@ -447,6 +446,8 @@ async def echo_client(message):
447446
assert message == data.decode()
448447
writer.close()
449448
await writer.wait_closed()
449+
# Signal we are ready to sleep
450+
sock.sendall(b"ready")
450451
await asyncio.sleep(SHORT_TIMEOUT)
451452
452453
async def echo_client_spam(server):
@@ -456,8 +457,10 @@ async def echo_client_spam(server):
456457
random.shuffle(msg)
457458
tg.create_task(echo_client("".join(msg)))
458459
await asyncio.sleep(0)
459-
# at least a 1000 tasks created
460-
sock.sendall(b"ready")
460+
# at least a 1000 tasks created. Each task will signal
461+
# when is ready to avoid the race caused by the fact that
462+
# tasks are waited on tg.__exit__ and we cannot signal when
463+
# that happens otherwise
461464
# at this point all client tasks completed without assertion errors
462465
# let's wrap up the test
463466
server.close()
@@ -489,8 +492,10 @@ async def main():
489492
p = subprocess.Popen([sys.executable, script_name])
490493
client_socket, _ = server_socket.accept()
491494
server_socket.close()
492-
response = client_socket.recv(1024)
493-
self.assertEqual(response, b"ready")
495+
for _ in range(1000):
496+
expected_response = b"ready"
497+
response = client_socket.recv(len(expected_response))
498+
self.assertEqual(response, expected_response)
494499
for _ in busy_retry(SHORT_TIMEOUT):
495500
try:
496501
all_awaited_by = get_all_awaited_by(p.pid)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.