diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 092c77651..edbb3d565 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -56,6 +56,12 @@ clear_stale_tmp() { } [ -z "${BL_INSIDE:-}" ] && clear_stale_tmp +steam_update_stuck() { + [ "$1" -lt 60 ] || steam_updates=0 + steam_updates=$((steam_updates + 1)) + [ "$steam_updates" -ge 3 ] +} + collect_steam_logs() { [ -n "${BL_DEBUG_DIR:-}" ] || return 0 local steam_root=${XDG_DATA_HOME:-$HOME/.local/share}/Steam @@ -839,9 +845,11 @@ BUSCONF /usr/local/bin/droiddeck-steam-desktop-ui & desktop_ui_pid=$! fi + steam_started=$SECONDS "$steam_root/steamrtarm64/steam" "${_bl_ui[@]}" "${_bl_cdp[@]}" "${_bl_lang[@]}" -clientbeta "$steam_channel" \ -no-cef-sandbox -cef-ozone-platform=x11 "${_bl_cef[@]}" "$@" rc=$? + steam_ran=$((SECONDS - steam_started)) if [ -n "$desktop_ui_pid" ]; then kill "$desktop_ui_pid" 2>/dev/null || true wait "$desktop_ui_pid" 2>/dev/null || true @@ -876,8 +884,7 @@ BUSCONF continue fi [ "$rc" -eq 42 ] || break - steam_updates=$((steam_updates + 1)) - if [ "$steam_updates" -ge 3 ]; then + if steam_update_stuck "$steam_ran"; then echo "== steam: asked to restart for an update $steam_updates times and it is not installing; the session stops here rather than loop" break fi diff --git a/tools/tests/test_steam_restart_cap.py b/tools/tests/test_steam_restart_cap.py new file mode 100644 index 000000000..1763bc77f --- /dev/null +++ b/tools/tests/test_steam_restart_cap.py @@ -0,0 +1,34 @@ +import re +import subprocess +import unittest +from pathlib import Path + +SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session" + + +def stuck_function(): + match = re.search(r"^steam_update_stuck\(\) \{\n.*?^\}\n", SESSION.read_text(), re.M | re.S) + return match.group(0) if match else None + + +class SteamRestartCapTest(unittest.TestCase): + def restarts(self, *seconds_up): + function = stuck_function() + self.assertIsNotNone(function, "droiddeck-session has no steam_update_stuck()") + script = function + "steam_updates=0\nfor up in %s; do\n" % " ".join(map(str, seconds_up)) + script += " if steam_update_stuck \"$up\"; then echo stop; else echo restart; fi\ndone\n" + return subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30, + check=True).stdout.split() + + def test_an_update_that_keeps_asking_at_once_is_stopped_on_the_third(self): + self.assertEqual(["restart", "restart", "stop"], self.restarts(11, 13, 9)) + + def test_restarts_of_a_client_that_stayed_up_are_never_stopped(self): + self.assertEqual(["restart"] * 5, self.restarts(75, 4000, 90, 600, 61)) + + def test_a_run_that_stayed_up_starts_the_count_again(self): + self.assertEqual(["restart", "restart", "restart", "restart", "stop"], self.restarts(12, 10, 300, 14, 8)) + + +if __name__ == "__main__": + unittest.main()