diff --git a/lib/feeb/db/repo/manager.ex b/lib/feeb/db/repo/manager.ex index f679af8..889b751 100644 --- a/lib/feeb/db/repo/manager.ex +++ b/lib/feeb/db/repo/manager.ex @@ -158,7 +158,6 @@ defmodule Feeb.DB.Repo.Manager do # If `caller_pid` had a normal death, emit a warning so they remember to properly release # the connection. This is likely an application bug - if reason == :normal do ("Process #{inspect(caller_pid)} died with :normal reason without releasing the " <> "#{key} connection #{inspect(repo_pid)} -- maybe you forgot to commit/rollback?") diff --git a/test/db/repo/manager_test.exs b/test/db/repo/manager_test.exs index 891105c..30034bf 100644 --- a/test/db/repo/manager_test.exs +++ b/test/db/repo/manager_test.exs @@ -216,9 +216,7 @@ defmodule Feeb.DB.Repo.ManagerTest do spawn_and_wait(fn -> Manager.fetch_connection(manager, :write, queue_timeout: :infinity) send(test_pid, :got_connection) - - # Keep this process alive until the end of the test - :timer.sleep(999_999) + block_forever() end) # Initially, both `spawn_pid_1` and `spawn_pid_2` are in the queue (in that order) @@ -249,9 +247,7 @@ defmodule Feeb.DB.Repo.ManagerTest do request_pid = spawn_and_wait(fn -> Manager.fetch_connection(manager, :write) - - # Keep this process alive until the test can end its execution - :timer.sleep(999_999) + block_forever() end) # The Repo.Manager currently has an active write_1 connection leased to `request_pid` @@ -276,14 +272,14 @@ defmodule Feeb.DB.Repo.ManagerTest do request_pid = spawn_and_wait(fn -> Manager.fetch_connection(manager, :write) - :timer.sleep(999_999) + block_forever() end) queued_request_pid = spawn_and_wait(fn -> # This guy is waiting for `request_pid` to release the connection Manager.fetch_connection(manager, :write) - :timer.sleep(999_999) + block_forever() end) # The write_1 connection is busy (leased to `request_pid`) and there is a non-empty queue diff --git a/test/support/utils.ex b/test/support/utils.ex index 1418236..3502d9b 100644 --- a/test/support/utils.ex +++ b/test/support/utils.ex @@ -23,4 +23,14 @@ defmodule Test.Utils do spawn_pid end + + @doc """ + Starts a receive block that will hang indefinitely. This is used for spawned processes that should + remain alive until the end of the test suite to avoid flakes. + """ + def block_forever do + receive do + :will_never_receive -> :ok + end + end end