mhanberg

mhanberg

Expert LSP Core Team

How to write feature tests using Wallaby that relies on a GenServer?

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

Marked As Solved

mhanberg

mhanberg

Expert LSP Core Team

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/3 which in turn did register the process with the module name.

Thanks for the help @keathley and @mbuhot.

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; somethi...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement