Even though I am using Phoenix, I do think my problem is more generic.
In my test, I create a record in the database. Subsequently I call a phx endpoint with a key (the Mac address).
Inside phoenix there is a plug that takes the Mac address, and queries a registry to see if a pid is already registered, if not a new process is created and this process registers itself.
If the record is not found in the database, the plug will return a 404.
Now when I run my tests in isolation they all work.
When I run my suite, they sometimes fail.
I tried adding async: true
in my test file, but it does not help.
The flow is as follows:
Request -> Findhotspot (plug) -> Hotspot.find -> HotspotSupervisor.find_or_create (DynamicSupervisor)
defmodule Gwapi.FindHotspot do
@moduledoc """
Get the MAC address from the querystring and
populate the connection with the found router
or return a 404
"""
import Plug.Conn
alias Gwapi.Hotspot
def init(_), do: []
def call(conn, _) do
case Hotspot.find(conn.params["mac"]) do
{:ok, hotspot} ->
assign(conn, :hotspot, hotspot)
err ->
IO.inspect err
conn |> send_resp(404, "") |> halt
end
end
end
I added the IO.inspect
to see what is happening, and it returns
{:error,
{{:shutdown, "owner #PID<0.552.0> exited with: shutdown"},
{GenServer, :call,
[
#PID<0.553.0>,
{:checkout, #Reference<0.3277896844.2305556481.205878>, true, :infinity},
5000
]}}}