mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
[3.13] gh-129441: Fix some flakiness in test_instrumentation (gh-141881) (gh-141914)
Some checks failed
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Lint / lint (push) Waiting to run
JIT / Interpreter (Debug) (push) Has been cancelled
JIT / aarch64-pc-windows-msvc/msvc (Release) (push) Has been cancelled
JIT / aarch64-pc-windows-msvc/msvc (Debug) (push) Has been cancelled
JIT / i686-pc-windows-msvc/msvc (Release) (push) Has been cancelled
JIT / i686-pc-windows-msvc/msvc (Debug) (push) Has been cancelled
JIT / aarch64-apple-darwin/clang (Release) (push) Has been cancelled
JIT / aarch64-unknown-linux-gnu/clang (Release) (push) Has been cancelled
JIT / aarch64-apple-darwin/clang (Debug) (push) Has been cancelled
JIT / aarch64-unknown-linux-gnu/clang (Debug) (push) Has been cancelled
JIT / aarch64-unknown-linux-gnu/gcc (Release) (push) Has been cancelled
JIT / aarch64-unknown-linux-gnu/gcc (Debug) (push) Has been cancelled
JIT / x86_64-pc-windows-msvc/msvc (Release) (push) Has been cancelled
JIT / x86_64-pc-windows-msvc/msvc (Debug) (push) Has been cancelled
JIT / x86_64-apple-darwin/clang (Release) (push) Has been cancelled
JIT / x86_64-unknown-linux-gnu/clang (Release) (push) Has been cancelled
JIT / x86_64-apple-darwin/clang (Debug) (push) Has been cancelled
JIT / x86_64-unknown-linux-gnu/clang (Debug) (push) Has been cancelled
JIT / x86_64-unknown-linux-gnu/gcc (Release) (push) Has been cancelled
JIT / x86_64-unknown-linux-gnu/gcc (Debug) (push) Has been cancelled
JIT / Free-Threaded (Debug) (push) Has been cancelled
Some checks failed
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Lint / lint (push) Waiting to run
JIT / Interpreter (Debug) (push) Has been cancelled
JIT / aarch64-pc-windows-msvc/msvc (Release) (push) Has been cancelled
JIT / aarch64-pc-windows-msvc/msvc (Debug) (push) Has been cancelled
JIT / i686-pc-windows-msvc/msvc (Release) (push) Has been cancelled
JIT / i686-pc-windows-msvc/msvc (Debug) (push) Has been cancelled
JIT / aarch64-apple-darwin/clang (Release) (push) Has been cancelled
JIT / aarch64-unknown-linux-gnu/clang (Release) (push) Has been cancelled
JIT / aarch64-apple-darwin/clang (Debug) (push) Has been cancelled
JIT / aarch64-unknown-linux-gnu/clang (Debug) (push) Has been cancelled
JIT / aarch64-unknown-linux-gnu/gcc (Release) (push) Has been cancelled
JIT / aarch64-unknown-linux-gnu/gcc (Debug) (push) Has been cancelled
JIT / x86_64-pc-windows-msvc/msvc (Release) (push) Has been cancelled
JIT / x86_64-pc-windows-msvc/msvc (Debug) (push) Has been cancelled
JIT / x86_64-apple-darwin/clang (Release) (push) Has been cancelled
JIT / x86_64-unknown-linux-gnu/clang (Release) (push) Has been cancelled
JIT / x86_64-apple-darwin/clang (Debug) (push) Has been cancelled
JIT / x86_64-unknown-linux-gnu/clang (Debug) (push) Has been cancelled
JIT / x86_64-unknown-linux-gnu/gcc (Release) (push) Has been cancelled
JIT / x86_64-unknown-linux-gnu/gcc (Debug) (push) Has been cancelled
JIT / Free-Threaded (Debug) (push) Has been cancelled
Most of the `self.assertTrue(self.called)` checks are flaky because
the worker threads may sometimes finish before the main thread calls
`self.during_threads()`.
(cherry picked from commit 71126ab19c)
Co-authored-by: Sam Gross <colesbury@gmail.com>
This commit is contained in:
parent
7905e85ecd
commit
9127013b56
1 changed files with 7 additions and 24 deletions
|
|
@ -9,7 +9,7 @@ import weakref
|
|||
|
||||
from sys import monitoring
|
||||
from test.support import threading_helper
|
||||
from threading import Thread, _PyRLock
|
||||
from threading import Thread, _PyRLock, Barrier
|
||||
from unittest import TestCase
|
||||
|
||||
|
||||
|
|
@ -34,10 +34,10 @@ class InstrumentationMultiThreadedMixin:
|
|||
return n
|
||||
return self.work(n - 1, funcs) + self.work(n - 2, funcs)
|
||||
|
||||
def start_work(self, n, funcs):
|
||||
def start_work(self, n, funcs, barrier):
|
||||
# With the GIL builds we need to make sure that the hooks have
|
||||
# a chance to run as it's possible to run w/o releasing the GIL.
|
||||
time.sleep(0.1)
|
||||
barrier.wait()
|
||||
self.work(n, funcs)
|
||||
|
||||
def after_test(self):
|
||||
|
|
@ -52,14 +52,16 @@ class InstrumentationMultiThreadedMixin:
|
|||
exec("def f(): pass", x)
|
||||
funcs.append(x["f"])
|
||||
|
||||
barrier = Barrier(self.thread_count + 1)
|
||||
threads = []
|
||||
for i in range(self.thread_count):
|
||||
# Each thread gets a copy of the func list to avoid contention
|
||||
t = Thread(target=self.start_work, args=(self.fib, list(funcs)))
|
||||
t = Thread(target=self.start_work, args=(self.fib, list(funcs), barrier))
|
||||
t.start()
|
||||
threads.append(t)
|
||||
|
||||
self.after_threads()
|
||||
barrier.wait()
|
||||
|
||||
while True:
|
||||
any_alive = False
|
||||
|
|
@ -119,7 +121,6 @@ class MonitoringMultiThreaded(
|
|||
def setUp(self):
|
||||
super().setUp()
|
||||
self.set = False
|
||||
self.called = False
|
||||
monitoring.register_callback(
|
||||
self.tool_id, monitoring.events.LINE, self.callback
|
||||
)
|
||||
|
|
@ -129,10 +130,7 @@ class MonitoringMultiThreaded(
|
|||
super().tearDown()
|
||||
|
||||
def callback(self, *args):
|
||||
self.called = True
|
||||
|
||||
def after_test(self):
|
||||
self.assertTrue(self.called)
|
||||
pass
|
||||
|
||||
def during_threads(self):
|
||||
if self.set:
|
||||
|
|
@ -150,16 +148,11 @@ class SetTraceMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
|
|||
|
||||
def setUp(self):
|
||||
self.set = False
|
||||
self.called = False
|
||||
|
||||
def after_test(self):
|
||||
self.assertTrue(self.called)
|
||||
|
||||
def tearDown(self):
|
||||
sys.settrace(None)
|
||||
|
||||
def trace_func(self, frame, event, arg):
|
||||
self.called = True
|
||||
return self.trace_func
|
||||
|
||||
def during_threads(self):
|
||||
|
|
@ -176,16 +169,11 @@ class SetProfileMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
|
|||
|
||||
def setUp(self):
|
||||
self.set = False
|
||||
self.called = False
|
||||
|
||||
def after_test(self):
|
||||
self.assertTrue(self.called)
|
||||
|
||||
def tearDown(self):
|
||||
sys.setprofile(None)
|
||||
|
||||
def trace_func(self, frame, event, arg):
|
||||
self.called = True
|
||||
return self.trace_func
|
||||
|
||||
def during_threads(self):
|
||||
|
|
@ -202,16 +190,11 @@ class SetProfileAllThreadsMultiThreaded(InstrumentationMultiThreadedMixin, TestC
|
|||
|
||||
def setUp(self):
|
||||
self.set = False
|
||||
self.called = False
|
||||
|
||||
def after_test(self):
|
||||
self.assertTrue(self.called)
|
||||
|
||||
def tearDown(self):
|
||||
threading.setprofile_all_threads(None)
|
||||
|
||||
def trace_func(self, frame, event, arg):
|
||||
self.called = True
|
||||
return self.trace_func
|
||||
|
||||
def during_threads(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue