From 225bf22a07954d988c0012d8570f571b29a8b8ac Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 13:48:33 -0700 Subject: [PATCH] fix(nix): KWin is asked for the outputs once a second, and longer timeouts --- nix/tests/vm/lib/komorebi_vm/kde.py | 29 +++++++++++++++++-- nix/tests/vm/suites/commands/default.nix | 2 +- nix/tests/vm/suites/core-e2e/default.nix | 2 +- nix/tests/vm/suites/core-lock/default.nix | 2 +- nix/tests/vm/suites/drag-resize/default.nix | 2 +- nix/tests/vm/suites/features/default.nix | 2 +- nix/tests/vm/suites/hotplug/default.nix | 2 +- nix/tests/vm/suites/placement/default.nix | 2 +- .../vm/suites/workspace-rules/default.nix | 2 +- 9 files changed, 35 insertions(+), 10 deletions(-) diff --git a/nix/tests/vm/lib/komorebi_vm/kde.py b/nix/tests/vm/lib/komorebi_vm/kde.py index 26b63e51..8c929221 100644 --- a/nix/tests/vm/lib/komorebi_vm/kde.py +++ b/nix/tests/vm/lib/komorebi_vm/kde.py @@ -15,6 +15,8 @@ from komorebi_vm.machine import Machine # a KWin script is told apart by its name in the journal, so each probe has a name of its own _PROBES = count(1) +# how long what KWin said of the outputs is kept, in seconds +SCREENS_TTL = 1.0 class Outputs: @@ -47,15 +49,18 @@ class Outputs: """Unplugs an output, as far as KWin can tell: it is disabled, and its windows go to the outputs that are left.""" self._kde.sh(f"kscreen-doctor output.{name}.disable") + self._kde.invalidate_screens() def enable(self, name: str) -> None: """Plugs an output back in, as far as KWin can tell.""" self._kde.sh(f"kscreen-doctor output.{name}.enable") + self._kde.invalidate_screens() def scale(self, name: str, factor: float) -> None: """Gives an output another scale: its size in pixels, as the windows see it, becomes its mode divided by `factor`.""" self._kde.sh(f"kscreen-doctor output.{name}.scale.{factor:g}") + self._kde.invalidate_screens() class Kde: @@ -704,13 +709,29 @@ class Kde: ) return [line for line in self.kwin_reports(name) if line != "done"] + _screens_cache: tuple[float, list[tuple[Rect, Rect]] | None] | None = None + + def invalidate_screens(self) -> None: + """Forgets what [`Kde.screens`][] last said: the outputs changed.""" + self._screens_cache = None + def screens(self) -> list[tuple[Rect, Rect]] | None: """What KWin says of each enabled output, left to right: its rectangle in the coordinates of the desktop, and the area of it that windows may take (KWin's placement area: the output less the panels, as the daemon's bridge reads it). `None` when KWin does not say. - A KWin script asks, because `kdotool` has no call for either. + A KWin script asks, because `kdotool` has no call for either, and a script is slow, so the + answer is kept for a second, and forgotten when the outputs are changed through + [`Outputs`][]. """ + now = time.monotonic() + if self._screens_cache is not None and now - self._screens_cache[0] < SCREENS_TTL: + return self._screens_cache[1] + found = self._read_screens() + self._screens_cache = (time.monotonic(), found) + return found + + def _read_screens(self) -> list[tuple[Rect, Rect]] | None: source = """ for (var i = 0; i < workspace.screens.length; i++) { var s = workspace.screens[i]; @@ -750,8 +771,12 @@ class Kde: def kwin_reports(self, name: str) -> list[str]: """Every line the KWin script `name` has reported so far ([`Kde.kwin_script`][]).""" - log = self.machine.execute(f"journalctl _UID={self.uid} --no-pager -o cat")[1] mark = f"KS:{name} " + # the guest picks the lines: the whole journal of the user, read back through the test + # driver on every call, is what made a run slower the longer it went + log = self.machine.execute( + f"journalctl _UID={self.uid} --no-pager -o cat | grep -F {shlex.quote(mark)}" + )[1] return [line.split(mark, 1)[1] for line in log.splitlines() if mark in line] @property diff --git a/nix/tests/vm/suites/commands/default.nix b/nix/tests/vm/suites/commands/default.nix index b51bc717..4128e533 100644 --- a/nix/tests/vm/suites/commands/default.nix +++ b/nix/tests/vm/suites/commands/default.nix @@ -1,5 +1,5 @@ { tier = "fast"; kind = "headless"; - timeoutMinutes = 15; + timeoutMinutes = 30; } diff --git a/nix/tests/vm/suites/core-e2e/default.nix b/nix/tests/vm/suites/core-e2e/default.nix index bb57ac90..44d856e4 100644 --- a/nix/tests/vm/suites/core-e2e/default.nix +++ b/nix/tests/vm/suites/core-e2e/default.nix @@ -1,5 +1,5 @@ { tier = "fast"; kind = "headless"; - timeoutMinutes = 10; + timeoutMinutes = 40; } diff --git a/nix/tests/vm/suites/core-lock/default.nix b/nix/tests/vm/suites/core-lock/default.nix index 91ff32cb..2ab6bfdf 100644 --- a/nix/tests/vm/suites/core-lock/default.nix +++ b/nix/tests/vm/suites/core-lock/default.nix @@ -1,5 +1,5 @@ { tier = "slow"; kind = "session"; - timeoutMinutes = 15; + timeoutMinutes = 20; } diff --git a/nix/tests/vm/suites/drag-resize/default.nix b/nix/tests/vm/suites/drag-resize/default.nix index 66c2aff7..b25b6191 100644 --- a/nix/tests/vm/suites/drag-resize/default.nix +++ b/nix/tests/vm/suites/drag-resize/default.nix @@ -1,7 +1,7 @@ { tier = "slow"; kind = "session"; - timeoutMinutes = 15; + timeoutMinutes = 20; # The module's unit starts komorebi when the session does, and the test drags against that # daemon, reading the drags it has handled from the unit's journal. The pointer is a uinput # device the session node has (komorebi_vm.Pointer). diff --git a/nix/tests/vm/suites/features/default.nix b/nix/tests/vm/suites/features/default.nix index f2a97096..5c1e28c0 100644 --- a/nix/tests/vm/suites/features/default.nix +++ b/nix/tests/vm/suites/features/default.nix @@ -1,7 +1,7 @@ { tier = "slow"; kind = "session"; - timeoutMinutes = 20; + timeoutMinutes = 25; # The module installs the effects and its unit starts komorebi when the session does. The first # section uses that daemon; the others stop it and run the unit themselves, once for each # feature. diff --git a/nix/tests/vm/suites/hotplug/default.nix b/nix/tests/vm/suites/hotplug/default.nix index b51bc717..41cabdba 100644 --- a/nix/tests/vm/suites/hotplug/default.nix +++ b/nix/tests/vm/suites/hotplug/default.nix @@ -1,5 +1,5 @@ { tier = "fast"; kind = "headless"; - timeoutMinutes = 15; + timeoutMinutes = 20; } diff --git a/nix/tests/vm/suites/placement/default.nix b/nix/tests/vm/suites/placement/default.nix index bb57ac90..b51bc717 100644 --- a/nix/tests/vm/suites/placement/default.nix +++ b/nix/tests/vm/suites/placement/default.nix @@ -1,5 +1,5 @@ { tier = "fast"; kind = "headless"; - timeoutMinutes = 10; + timeoutMinutes = 15; } diff --git a/nix/tests/vm/suites/workspace-rules/default.nix b/nix/tests/vm/suites/workspace-rules/default.nix index bb57ac90..b51bc717 100644 --- a/nix/tests/vm/suites/workspace-rules/default.nix +++ b/nix/tests/vm/suites/workspace-rules/default.nix @@ -1,5 +1,5 @@ { tier = "fast"; kind = "headless"; - timeoutMinutes = 10; + timeoutMinutes = 15; }