Intermittent DBConnection.ConnectionError in tests

I do have some of those still happening but the runs of tests on the CI vs local are quite different so it’s difficult to pinpoint the issue.

Before my change, none of the test runs would pass. Now they do pass but they randomly fail.

Locally I mostly have such errors:

[error] Postgrex.Protocol (#PID<0.1316.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.19767.0> exited

or

[error] Child #Reference<0.3366742383.3747086337.132479> of Supervisor #PID<0.14032.0> (Supervisor.Default) shut down abnormally
** (exit) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
Pid: #PID<0.14034.0>
Start Call: Phoenix.LiveView.Channel.start_link/?

Whereas on the CI, I have errors related to the assert_value package:

[error] GenServer AssertValue.Server terminating
** (stop) exited in: GenServer.call(#PID<0.1074.0>, :flush, 5000)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
    (elixir 1.15.6) lib/gen_server.ex:1074: GenServer.call/3
    (assert_value 0.10.1) lib/assert_value/server.ex:68: AssertValue.Server.handle_cast/2
    (stdlib 5.1) gen_server.erl:1103: :gen_server.try_handle_cast/3
    (stdlib 5.1) gen_server.erl:1165: :gen_server.handle_msg/6
    (stdlib 5.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Last message: {:"$gen_cast", {:flush_ex_unit_io}}

[error] Process AssertValue.Server (#PID<0.903.0>) terminating
** (exit) exited in: GenServer.call(#PID<0.1074.0>, :flush, 5000)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
    (elixir 1.15.6) lib/gen_server.ex:1074: GenServer.call/3
    (assert_value 0.10.1) lib/assert_value/server.ex:68: AssertValue.Server.handle_cast/2
    (stdlib 5.1) gen_server.erl:1103: :gen_server.try_handle_cast/3
    (stdlib 5.1) gen_server.erl:1165: :gen_server.handle_msg/6
    (stdlib 5.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Initial Call: AssertValue.Server.init/1
Ancestors: [#PID<0.902.0>, #PID<0.901.0>]

I’m still trying to find why I get some of these random errors.

They mostly appeared when switching to Elixir 1.15.6 (+ erlang 26.1) and upgrading some packages like phoenix_live_view to 0.18.18.

1 Like

I’ve found this common pattern to cause ConnectionError in passing tests:

# flaky
assert view
       |> element("#some-button-id")
       |> render_click()
       |> follow_redirect(conn, "/destination/path")

# better
view
|> element("#some-button-id")
|> render_click()

assert_redirected(view, "/destination/path")
1 Like

I’ve tried updating my tests to follow this pattern, but I’m still getting those errors.

I’ve created an issue here: Intermittent DBConnection.ConnectionError in tests · Issue #3545 · phoenixframework/phoenix_live_view · GitHub

I think you’re misunderstanding the comment you replied to. They’re saying that they’re doing something common which shouldn’t cause an error but does cause an error. I don’t think they’re saying that that the pattern will fix the error.