Skip to content

Commit d86ddd5

Browse files
committed
Add diagnostics for flaky test_regrtest worker bug
When worker JSON parsing fails with AttributeError, include raw JSON content and data keys in the error message to help diagnose the intermittent 'TestResult object has no attribute state' failure.
1 parent 676325e commit d86ddd5

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

Lib/test/libregrtest/result.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ def _decode_test_result(data: dict[str, Any]) -> TestResult | dict[str, Any]:
238238
data['covered_lines'] = [
239239
tuple(loc) for loc in data['covered_lines']
240240
]
241-
return TestResult(**data)
241+
# TODO: RUSTPYTHON; diagnostics for flaky worker bug
242+
try:
243+
result = TestResult(**data)
244+
except AttributeError:
245+
raise AttributeError(
246+
f"TestResult(**data) failed; keys={sorted(data.keys())}, "
247+
f"slots={getattr(TestResult, '__slots__', 'N/A')}, "
248+
f"data={data!r}"
249+
)
250+
return result
242251
else:
243252
return data

Lib/test/libregrtest/run_workers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,10 @@ def read_json(self, json_file: JsonFile, json_tmpfile: TextIO | None,
347347
except Exception as exc:
348348
# gh-101634: Catch UnicodeDecodeError if stdout cannot be
349349
# decoded from encoding
350-
err_msg = f"Failed to parse worker process JSON: {exc}"
350+
# TODO: RUSTPYTHON; include JSON for debugging flaky worker bugs
351+
json_preview = worker_json[:500] if len(worker_json) > 500 else worker_json
352+
err_msg = (f"Failed to parse worker process JSON: {exc}\n"
353+
f" JSON ({len(worker_json)} bytes): {json_preview!r}")
351354
raise WorkerError(self.test_name, err_msg, stdout,
352355
state=State.WORKER_BUG)
353356

Lib/test/libregrtest/worker.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ def worker_process(worker_json: StrJSON) -> NoReturn:
110110
"`test.cov` not found in sys.modules but coverage wanted"
111111
)
112112

113+
# TODO: RUSTPYTHON; diagnostics for flaky worker bug
114+
# Verify TestResult attributes are accessible before JSON encoding
115+
try:
116+
_ = result.state
117+
_ = result.test_name
118+
except AttributeError as e:
119+
print(f"WORKER BUG: TestResult slot access failed before encoding: {e}",
120+
file=sys.stderr, flush=True)
121+
print(f" result type: {type(result)}, slots: {getattr(type(result), '__slots__', 'N/A')}",
122+
file=sys.stderr, flush=True)
123+
113124
if json_file.file_type == JsonFileType.STDOUT:
114125
print()
115126
result.write_json_into(sys.stdout)

0 commit comments

Comments
 (0)