From 63be3a6eb3731c2b7fa4952dab86554a99bf22a3 Mon Sep 17 00:00:00 2001 From: milk4sale <53350507+milk4sale@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:29:32 -0600 Subject: [PATCH] tests: each fake test of the --jobs tests logs to a file of its own (TEST-WINE-JOBS-TIMING-LOG) tests/test_run_wine_tests.py fails on Windows since #1354 added the --jobs tests: in the check job's loop it failed in 2 of 4 runs on a windows-latest runner, in MainTest.test_jobs_keeps_locks_serial_tests_and_dependencies, once with "KeyError: 'after'" and once with "IndexError: list index out of range" in overlap(). It passes on Linux and macOS. The job's 15-minute limit cancels it before it prints its list of failed files, which is why nobody saw it. The fake test programs of those tests run several at a time, and each appended its "start" and "end" line to one timing.log with open(log, 'a').write(...). On Windows an append from another process is not atomic: both writers find the same end of file and one line replaces the other. A test whose lines are both lost is missing from the result (the KeyError), one that lost a line has a single timestamp (the IndexError, or "not enough values to unpack" in most_at_once), and a mangled line fails in intervals(). Each fake test now gets its own log (timing..log) and intervals() reads them all. The tests assert what they asserted before. Measured on GitHub's runners with Python 3.12 (a scratch branch on a fork, each system once): - four processes that append two lines each to one file at the same moment, 150 rounds: a line was lost in 150 rounds on windows-latest and in none on ubuntu-24.04 and macos-26; with a file per process, in none anywhere; - the two --jobs tests run 60 times: 60 failures on windows-latest before this change and none after; none before or after on ubuntu-24.04 and macos-26. Co-Authored-By: Claude Fable 5.2 --- tests/test_run_wine_tests.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/test_run_wine_tests.py b/tests/test_run_wine_tests.py index 7ba55d2f8e..8c1f214f5f 100644 --- a/tests/test_run_wine_tests.py +++ b/tests/test_run_wine_tests.py @@ -601,7 +601,8 @@ def test_no_wineserver_is_one_line_and_the_run_goes_on(self): self.assertIn("[PASS] ok", out) def timed(self, name, *, props=None, code=0, sleep=0.3): - """A test that logs when it starts and ends, to see which tests overlapped.""" + """A test that logs when it starts and ends, to see which tests overlapped. Each has a log of its own: on + Windows, lines that several processes append to one file at the same moment overwrite each other.""" (self.artifact / f"{name}.py").write_text( "import os, sys, time\n" "log = os.environ['TIMING_LOG']\n" @@ -610,14 +611,15 @@ def timed(self, name, *, props=None, code=0, sleep=0.3): f"open(log, 'a').write('{name} end %r\\n' % time.monotonic())\n" f"sys.exit({code})\n", encoding="utf-8", newline="\n") props = dict(props or {}) - props["ENVIRONMENT"] = ["TIMING_LOG=" + str(self.root / "timing.log")] + props["ENVIRONMENT"] = ["TIMING_LOG=" + str(self.root / f"timing.{name}.log")] return ctest_entry(name, self.command(f"{name}.py"), props) def intervals(self): spans: dict[str, list[float]] = {} - for line in (self.root / "timing.log").read_text(encoding="utf-8").splitlines(): - name, _, when = line.split() - spans.setdefault(name, []).append(float(when)) + for log in sorted(self.root.glob("timing.*.log")): + for line in log.read_text(encoding="utf-8").splitlines(): + name, _, when = line.split() + spans.setdefault(name, []).append(float(when)) return spans @staticmethod