I have gone through a few iterations of getting this test to work, and I’ve reach the point where my GenServer is started by the test and will have the same database connection as the test (the GenServer needs to access the database).
But it seems now that when my controller attempts to call the GenServer, it doesn’t look to be started, as I see this error
|| 08:30:30.194 [error] #PID<0.487.0> running AppWeb.Endpoint (cowboy_protocol) terminated
|| Server: localhost:4001 (http)
|| Request: GET /
|| ** (exit) exited in: GenServer.call(App.Core.AppServer, :status, 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
So with that said, does anyone have any general advice for writing Wallaby tests for endpoints that utilize a GenServer? I feel like I may have missed something along the way. (Help with this specific problem is also appreciated.)
Thanks everyone!
branch on github in case the snippets below are not sufficient
Controller that access the GenServer
defmodule AppWeb.ThingController do
use AppWeb, :controller
alias App.Core.AppServer
def index(conn, _) do
thing = AppServer.status(AppServer)
conn
|> render(:index, thing: thing)
end
end
Wallaby test.
test "should display things on the home page", %{session: session} do
thing_fixture(%{
name: "name",
url: "url"
})
start_supervised!(FeedServer)
session
|> visit("/")
|> assert_text("Some text")
end
Note: I only don’t start the GenServer in the test environment, so I’m able to start it in the context of the test and will be supervised by the test supervisor.
defmodule App.Application do
use Application
def start(_type, _args) do
children =
[
App.Repo,
AppWeb.Endpoint
] ++ Application.get_env(:app, :app_server)
opts = [strategy: :one_for_one, name: App.Supervisor]
Supervisor.start_link(children, opts)
end
def config_change(changed, _new, removed) do
AppWeb.Endpoint.config_change(changed, removed)
:ok
end
end