I have a test in my Phoenix app that is testing a Phoenix.PubSub
subscriber that uses Genserver. The subscriber does some database work as part of its handle_info/2
.
test "sending creating a referral code upon user registration" do
start_supervised(MyApp.Accounts.Subscriber)
user = insert(:user)
Phoenix.PubSub.broadcast(MappApp.PubSub, "accounts", {:register, user})
assert_eventually(Repo.exists?(ReferralCode))
stop_supervised(MyApp.Accounts.Subscriber)
end
Running this test module by itself is fine. However when I run my entire test suite I get an error like so (the test still passes):
[error] GenServer MyApp.Accounts.Subscriber terminating
** (stop) exited in: DBConnection.Holder.checkout(#PID<0.970.0>, [log: #Function<9.124843621/1 in Ecto.Adapters.SQL.with_log/3>, cache_statement: "ecto_insert_referral_codes", timeout: 15000, pool_size: 10, pool: DBConnection.Ownership])
** (EXIT) shutdown: "owner #PID<0.969.0> exited"
<stacktrace...>
This looks like it's an issue with the database connection still being open when the process is terminated so it doesn't die gracefully. But I'm not sure how to deal with this.
Any advice on how to prevent this error?
async: true
? If so, that could be the culprit. – zwippieuse
ing theModelCase
module. Is this the default behaviour? – harryguse ModelCase
(and notuse ModelCase, async: true
) then the tests in the module will not run concurrently with tests in other modules, which is probably what you want. (Although I don't know what your ModelCase looks like) – zwippieDataCase
in current Phoenix: github.com/phoenixframework/phoenix/blob/master/installer/…). – harrygasync: false
and the same error occurs. I think theModelCase
runs the test non-async – harryg