Skip to content

gh-109162: libregrtest: fix _decode_worker_job() #109202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/libregrtest/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ def iter_tests(self):
else:
yield from self.tests

@staticmethod
def from_json_dict(json_dict):
if json_dict['hunt_refleak']:
json_dict['hunt_refleak'] = HuntRefleak(**json_dict['hunt_refleak'])
return RunTests(**json_dict)


# Minimum duration of a test to display its duration or to mention that
# the test is running in background
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/runtest_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def default(self, o: Any) -> dict[str, Any]:
def _decode_worker_job(d: dict[str, Any]) -> WorkerJob | dict[str, Any]:
if "__worker_job__" in d:
d.pop('__worker_job__')
d['runtests'] = RunTests(**d['runtests'])
d['runtests'] = RunTests.from_json_dict(d['runtests'])
return WorkerJob(**d)
if "__namespace__" in d:
d.pop('__namespace__')
Expand Down
18 changes: 14 additions & 4 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,12 +1018,16 @@ def test_run(self):
stats=TestStats(4, 1),
forever=True)

def check_leak(self, code, what):
def check_leak(self, code, what, *, multiprocessing=False):
test = self.create_test('huntrleaks', code=code)

filename = 'reflog.txt'
self.addCleanup(os_helper.unlink, filename)
output = self.run_tests('--huntrleaks', '6:3:', test,
cmd = ['--huntrleaks', '6:3:']
if multiprocessing:
cmd.append('-j1')
cmd.append(test)
output = self.run_tests(*cmd,
exitcode=EXITCODE_BAD_TEST,
stderr=subprocess.STDOUT)
self.check_executed_tests(output, [test], failed=test, stats=1)
Expand All @@ -1039,7 +1043,7 @@ def check_leak(self, code, what):
self.assertIn(line2, reflog)

@unittest.skipUnless(support.Py_DEBUG, 'need a debug build')
def test_huntrleaks(self):
def check_huntrleaks(self, *, multiprocessing: bool):
# test --huntrleaks
code = textwrap.dedent("""
import unittest
Expand All @@ -1050,7 +1054,13 @@ class RefLeakTest(unittest.TestCase):
def test_leak(self):
GLOBAL_LIST.append(object())
""")
self.check_leak(code, 'references')
self.check_leak(code, 'references', multiprocessing=multiprocessing)

def test_huntrleaks(self):
self.check_huntrleaks(multiprocessing=False)

def test_huntrleaks_mp(self):
self.check_huntrleaks(multiprocessing=True)

@unittest.skipUnless(support.Py_DEBUG, 'need a debug build')
def test_huntrleaks_fd_leak(self):
Expand Down