Skip to content

Commit cb80ccc

Browse files
committed
fix(test): add catch-all handle_call clause to TestReduxProcess
Added a catch-all handle_call/3 clause to TestReduxProcess test module to handle unsupported messages gracefully. The test was expecting the process to crash when sending an invalid message, but the better pattern is to return an error tuple. Changes: - Added catch-all handle_call/3 clause that returns {:error, {:unsupported_message, msg}} - Updated test to expect error tuple instead of process crash - Grouped all handle_call clauses together to satisfy Elixir's clause grouping requirement This fixes the FunctionClauseError that was causing test failures in CI.
1 parent 5177015 commit cb80ccc

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

test/phoenix/session_process/live_view_test.exs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ defmodule Phoenix.SessionProcess.LiveViewTest do
4848
{:reply, {:ok, Redux.get_state(new_redux)}, %{state | redux: new_redux}}
4949
end
5050

51+
# Catch-all for unsupported messages
52+
@impl true
53+
def handle_call(msg, _from, state) do
54+
{:reply, {:error, {:unsupported_message, msg}}, state}
55+
end
56+
5157
@impl true
5258
def handle_cast({:dispatch_async, action}, state) do
5359
new_redux = Redux.dispatch(state.redux, action, &reducer/2)
@@ -181,21 +187,11 @@ defmodule Phoenix.SessionProcess.LiveViewTest do
181187
test "returns error for unsupported state_key", %{session_id: session_id} do
182188
socket = %{assigns: %{}}
183189

184-
# Call with an unsupported message - this will crash the session process
185-
# So we need to catch the exit
186-
Process.flag(:trap_exit, true)
187-
188-
result =
189-
try do
190-
SessionLV.mount_session(socket, session_id, @pubsub_name, :invalid_message)
191-
catch
192-
:exit, _ -> {:error, :process_crashed}
193-
end
194-
195-
# Should get an error (either from timeout or process crash)
196-
assert match?({:error, _}, result)
190+
# Call with an unsupported message - should return an error tuple
191+
result = SessionLV.mount_session(socket, session_id, @pubsub_name, :invalid_message)
197192

198-
Process.flag(:trap_exit, false)
193+
# Should get an error response from the catch-all handle_call clause
194+
assert {:error, {:unsupported_message, :invalid_message}} = result
199195
end
200196
end
201197

0 commit comments

Comments
 (0)