mhanberg
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
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
keathley
Another way to handle this might be to disable the async flag for this test case. If you do that then you can explicitly terminate your gen_server once your test is done. Thats the tactic that we employed at my last job anyway.
mbuhot
Was
AppServerrenamed toFeedServer?mhanberg
Sorry, it should say
AppServer, it appears I wasn’t thorough enough in the censoring of my snippets.mhanberg
I have async disabled for these tests.
I believe that when you start a process with
start_supervisedit will get terminated at the end of the test.I haven’t had a lot of time to work on this, but I’ll update the thread once I find a solution.
Thanks!
mhanberg
I have gotten to the bottom of this error, and I am quite embarrassed as to the cause.
In an attempt to clean up how my genserver was started, I accidentally removed the third argument to
GenServer.start_link/3which in turn did register the process with the module name.Thanks for the help @keathley and @mbuhot.