r11na
I’m having difficult figuring out how to stop supervisors running genservers during my tests and I haven’t found any helpful guides online.
I have the following setup in a test file:
setup do
{:ok, server_pid} = Program.Myserver.start_link()
{:ok, server: server_pid}
end
When I run my tests I get an
** (MatchError) no match of right hand side value: {:error, {:already_started, pid<0.405.0>}}
No doubt because the supervisor has already started the genserver but I don’t know how to stop it doing this during my tests…
Any ideas on the best way to stop this?
Trending in Questions
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
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
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
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
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
OvermindDL1
You just need to tear it down after, see another thread already talking about this at:
michalmuskala
Since Elixir 1.5 the recommened approach for starting processes in a test is to use
start_supervised/2. This is an easy way to ensure the process is started and stopped together with the test process.r11na
I tried to do this:
But I get the below error…
r11na
Is there like an example project where this is done with start_supervised?
I see lots of snippets of code but I can’t seem to get any of them working…and I don’t quite know what the error message wants me to fix…
blatyo
The
setupcallback needs you to return one of those types. Like:The other issue appears to be that
CeresCore.Queue.Consumers.PaymentConsumer.start_link/1is not a function that exists.r11na
I’ve changed my setup call back to what you specified and that fixed one error, so I’m one step closer…
and I made the start_link function as follows to define start_link/1
However start_supervised still returns already_started error…
blatyo
What I typically do for this situation is set something like this in
config/test.exs:Then in my application supervisor, I separate out the processes I don’t want to start automatically and check the env.
If there’s a better way than this, I’m not aware of it.
r11na
Thats seems helpful but I’m still unable to just get the tests running sadly.
When I try to do it it just results in lower level supervisors not running…
The application itself works fine… but the tests won’t start.
Is there anywhere to find a full working example of using start_supervised?
So I can do a line by line comparison with my code.
All I find are snippets but they just aren’t working for me.
edit I was able to get get it sort of working now by conditionally loading genservers based on the environment. Seems clunky having to litter every single supervisor with an environment check, but I guess thats what has to be done.
Thanks for your help.
SZJX
I think the OP’s problem is that they defined some GenServer to be started in
application.ex, but wants to start the same server under the test setup block, therefore encountered the:already_startederror. It’s not the same issue as the one in the link you provided.SZJX
It seems that the easiest way to solve it is just to start your GenServer under a different name, using the
:nameoption? Though if your GenServer functions depend on a hardcoded:namesuch as__MODULE__it would indeed making testing harder.e.g. instead of writing
write
and then the child spec:
then in your test you can give a different name, e.g.