From 8dd20f6a80e7b5d6cec4e053004f878ce3f58537 Mon Sep 17 00:00:00 2001 From: Okachamie Date: Tue, 24 Nov 2026 18:24:07 -0500 Subject: [PATCH] tests: warm an adopted persistent wineserver --- scripts/run_wine_tests.py | 16 ++++++++++------ tests/test_run_wine_tests.py | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/scripts/run_wine_tests.py b/scripts/run_wine_tests.py index d360114303..b7c55afa6a 100644 --- a/scripts/run_wine_tests.py +++ b/scripts/run_wine_tests.py @@ -190,6 +190,14 @@ def _run(self, *flags, timeout=30.0) -> int | None: except (OSError, subprocess.TimeoutExpired): return None + def _warmup(self) -> None: + env = dict(os.environ, WINEDLLOVERRIDES=merge_dll_overrides(os.environ.get("WINEDLLOVERRIDES"))) + try: + subprocess.run(self.wine + ["wineboot"], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, env=env, timeout=120) + except (OSError, subprocess.TimeoutExpired): + pass # the tests start the services then, as without a kept server + def __enter__(self): if not self.command: self.note = "no wineserver found: each test starts its own" @@ -200,18 +208,14 @@ def __enter__(self): code = self._run("-p") else: self.note = "a wineserver already runs for this prefix: used and left running" + self._warmup() return self self.started = code == 0 if not self.started: self.note = f"could not start {self.command} -p: each test starts its own server" return self self.note = "wineserver kept alive for the run" - env = dict(os.environ, WINEDLLOVERRIDES=merge_dll_overrides(os.environ.get("WINEDLLOVERRIDES"))) - try: - subprocess.run(self.wine + ["wineboot"], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, env=env, timeout=120) - except (OSError, subprocess.TimeoutExpired): - pass # the tests start the services then, as without a kept server + self._warmup() return self def __exit__(self, *exc): diff --git a/tests/test_run_wine_tests.py b/tests/test_run_wine_tests.py index 7ba55d2f8e..6ef49adde7 100644 --- a/tests/test_run_wine_tests.py +++ b/tests/test_run_wine_tests.py @@ -594,6 +594,20 @@ def test_a_server_still_shutting_down_is_waited_for(self): self.assertEqual(code, 0) self.assertEqual(log.read_text(encoding="utf-8").splitlines(), ["-p", "-w", "-p", "-k"]) + def test_an_existing_persistent_server_is_warmed_but_not_stopped(self): + with mock.patch.object(rwt.KeptServer, "_run", side_effect=[2, 1]) as server, \ + mock.patch.object(rwt.subprocess, "run") as warm: + kept = rwt.KeptServer("wineserver", [sys.executable]) + with kept: + self.assertFalse(kept.started) + self.assertIn("used and left running", kept.note) + self.assertEqual(server.call_args_list, [mock.call("-p"), mock.call("-w", timeout=15.0)]) + warm.assert_called_once() + self.assertEqual(warm.call_args.args[0], [sys.executable, "wineboot"]) + self.assertIs(warm.call_args.kwargs["stdout"], subprocess.DEVNULL) + self.assertIs(warm.call_args.kwargs["stderr"], subprocess.DEVNULL) + self.assertEqual(warm.call_args.kwargs["timeout"], 120) + def test_no_wineserver_is_one_line_and_the_run_goes_on(self): code, out, _ = self.run_main([ctest_entry("ok", self.command("ok.py"))], "--require", "ok") self.assertEqual(code, 0)