Skip to content

Commit 4d3f628

Browse files
vstinnernascheme
andauthored
[3.14] Backport regrtest changes from the main branch (#163045) (#163056)
[3.15] Backport regrtest changes from the main branch (#163045) * gh-155981: Store refleak deltas in arrays (gh-55982) Store per-run deltas in array objects rather than lists of pooled integers. Large, unique deltas could otherwise grow int_pool and make the refleak checker report its own retained integers as reference leaks. (cherry picked from commit b38e073) * Fix regrtest rerun: reset worker_bug (#162293) When a test fails with "worker bug" and tests are rerun in verbose mode, reset worker_bug so that tests are marked as success if the failed test doesn't fail again when rerun in verbose mode. TestResult.write_json_into(file) now calls also file.flush(). (cherry picked from commit f84083b) * Do not rerun failed tests in regrtest on worker bug (#162780) When a test fails with "worker bug", no longer reruns failed tests in verbose mode. Previously, re-running tests in verbose mode failed to run a test called "<regrtest worker>". (cherry picked from commit 352cc06) --------- (cherry picked from commit 8ea5514) Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
1 parent 9b88897 commit 4d3f628

4 files changed

Lines changed: 19 additions & 19 deletions

File tree

‎Lib/test/libregrtest/main.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,12 @@ def _run_tests(self, selected: TestTuple, tests: TestList | None) -> int:
566566
coverage = self.results.get_coverage_results()
567567
self.display_result(runtests)
568568

569-
if self.want_rerun and self.results.need_rerun():
570-
self.rerun_failed_tests(runtests)
569+
if not self.results.worker_bug:
570+
if self.want_rerun and self.results.need_rerun():
571+
self.rerun_failed_tests(runtests)
571572

572-
if self.want_bisect and self.results.need_rerun():
573-
self.run_bisect(runtests)
573+
if self.want_bisect and self.results.need_rerun():
574+
self.run_bisect(runtests)
574575
finally:
575576
if use_load_tracker:
576577
self.logger.stop_load_tracker()

‎Lib/test/libregrtest/refleak.py‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
import warnings
4+
from array import array
45
from inspect import isabstract
56
from typing import Any
67
import linecache
@@ -93,24 +94,20 @@ def runtest_refleak(test_name, test_func,
9394
for obj in abc.__subclasses__() + [abc]:
9495
abcs[obj] = _get_dump(obj)[0]
9596

96-
# bpo-31217: Integer pool to get a single integer object for the same
97-
# value. The pool is used to prevent false alarm when checking for memory
98-
# block leaks. Fill the pool with values in -1000..1000 which are the most
99-
# common (reference, memory block, file descriptor) differences.
100-
int_pool = {value: value for value in range(-1000, 1000)}
101-
def get_pooled_int(value):
102-
return int_pool.setdefault(value, value)
103-
10497
warmups = hunt_refleak.warmups
10598
runs = hunt_refleak.runs
10699
filename = hunt_refleak.filename
107100
repcount = warmups + runs
108101

109-
# Pre-allocate to ensure that the loop doesn't allocate anything new
102+
# Pre-allocate to ensure that the loop doesn't allocate anything new.
103+
# Store the deltas as raw values in arrays rather than as int objects in
104+
# lists: each unique delta stored as an object would live until the end of
105+
# the loop and show up in the following repetition's reference and memory
106+
# block deltas (gh-75400, gh-155981).
110107
rep_range = list(range(repcount))
111-
rc_deltas = [0] * repcount
112-
alloc_deltas = [0] * repcount
113-
fd_deltas = [0] * repcount
108+
rc_deltas = array('q', [0]) * repcount
109+
alloc_deltas = array('q', [0]) * repcount
110+
fd_deltas = array('q', [0]) * repcount
114111
getallocatedblocks = sys.getallocatedblocks
115112
gettotalrefcount = sys.gettotalrefcount
116113
getunicodeinternedsize = sys.getunicodeinternedsize
@@ -154,9 +151,9 @@ def get_pooled_int(value):
154151
rc_after = gettotalrefcount()
155152
fd_after = fd_count()
156153

157-
rc_deltas[i] = get_pooled_int(rc_after - rc_before)
158-
alloc_deltas[i] = get_pooled_int(alloc_after - alloc_before)
159-
fd_deltas[i] = get_pooled_int(fd_after - fd_before)
154+
rc_deltas[i] = rc_after - rc_before
155+
alloc_deltas[i] = alloc_after - alloc_before
156+
fd_deltas[i] = fd_after - fd_before
160157

161158
if not quiet:
162159
# use max, not sum, so total_leaks is one of the pooled ints

‎Lib/test/libregrtest/result.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def get_rerun_match_tests(self) -> FilterTuple | None:
222222

223223
def write_json_into(self, file) -> None:
224224
json.dump(self, file, cls=_EncodeTestResult)
225+
file.flush()
225226

226227
@staticmethod
227228
def from_json(worker_json: StrJSON) -> 'TestResult':

‎Lib/test/libregrtest/results.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def prepare_rerun(self, *, clear: bool = True) -> tuple[TestTuple, FilterDict]:
171171
self.bad.clear()
172172
self.env_changed.clear()
173173
self.rerun_results.clear()
174+
self.worker_bug = False
174175

175176
return (tuple(tests), match_tests_dict)
176177

0 commit comments

Comments
 (0)