mhanberg

mhanberg

Expert LSP Core Team

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

Showing Posts 1 to 5

keathley

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

mbuhot

Was AppServer renamed to FeedServer?

mhanberg

mhanberg OP

Expert LSP Core Team

Sorry, it should say AppServer, it appears I wasn’t thorough enough in the censoring of my snippets.

mhanberg

mhanberg OP

Expert LSP Core Team

I have async disabled for these tests.

I believe that when you start a process with start_supervised it 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

mhanberg OP

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews