From c82e267dfba071ceab02b37fe7ad570784079c7b Mon Sep 17 00:00:00 2001 From: JohnnyT Date: Sat, 28 Nov 2026 06:39:50 -0700 Subject: [PATCH] Pins the crash report wait with a slow crash The screen editor page's crash report tests wait for the crashing process to exit before they read the capture, but none of them could tell if the wait was dropped: a real page crash logs its report too fast to race. A new test crashes a process that sleeps in terminate/2, which runs before the report is logged, so the report lands late on demand. It fails when wait_for_crash_report/1 returns without waiting; that mutation was run and turned the test red on its assertion. The helper's comment says the calls in the other tests are not each pinned, since a real page crash cannot be slowed. Refs: se-4426 --- .../live/screen_editor_live_test.exs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/statifier_examples_web/live/screen_editor_live_test.exs b/test/statifier_examples_web/live/screen_editor_live_test.exs index eb2a97da..ff5e0275 100644 --- a/test/statifier_examples_web/live/screen_editor_live_test.exs +++ b/test/statifier_examples_web/live/screen_editor_live_test.exs @@ -409,6 +409,23 @@ defmodule StatifierExamplesWeb.ScreenEditorLiveTest do assert log =~ ~s(Last message: %Phoenix.Socket.Message{) assert log =~ ~s("responses" => "[FILTERED]") end + + # Sabotage: made wait_for_crash_report/1 return at once; the capture + # closed before the slow process had logged its report, then + # reverted. + test "the wait holds the capture open for a report that is logged late" do + log = + debug_log(fn -> + {:ok, pid} = + GenServer.start(StatifierExamplesWeb.ScreenEditorLiveTest.SlowCrashing, nil) + + send(pid, :crash) + wait_for_crash_report(pid) + end) + + assert log =~ "terminating" + assert log =~ "the page crashed slowly" + end end defmodule Crashing do @@ -422,6 +439,22 @@ defmodule StatifierExamplesWeb.ScreenEditorLiveTest do def handle_info(_message, _state), do: raise("the page crashed") end + # Crashes, then takes its time in terminate/2, which runs before the crash + # report is logged: a report that lands late, on demand. + defmodule SlowCrashing do + @moduledoc false + use GenServer + + @impl true + def init(state), do: {:ok, state} + + @impl true + def handle_info(_message, _state), do: raise("the page crashed slowly") + + @impl true + def terminate(_reason, _state), do: Process.sleep(200) + end + defmodule RaisingSealer do @moduledoc false def seal(_plaintext), do: raise("the sealer is unavailable") @@ -482,6 +515,11 @@ defmodule StatifierExamplesWeb.ScreenEditorLiveTest do # it exits, so the report is in the capture once the process is down. The # wait is on that exit, by a monitor, and bounded: a process that never # goes down fails here, by name, rather than as a missing line later. + # The wait is pinned by the slow crash test, which logs its report late + # on purpose. The calls in the tests above are not each pinned: the + # report of a real page crash cannot be slowed on demand, so a call + # dropped from one of them still passes here and stays a robustness + # measure against a slow machine. defp wait_for_crash_report(pid) do ref = Process.monitor(pid)