blisscs
How do you run test in your umbrella app? When some apps want to use --no-start and some wants to normal behaviour
Hi I am wondering how should I run test for my umbrella app.
given in the umbrella app there are -
- apps that want to start supervision tree manually while testing- usually we use
mix test --no-startin the individual app. See about this more here - Elixir: Testing without starting supervision tree. ( I am doing this due to, I want to setup and mock network calls and also test that what is sent on network is what I want during supervision loads). - apps that wants to start supervision tree - usually we use
mix test - Some of my apps has ecto as it dependency - usually we alias `test: [‘ecto.create --quite’, ‘ecto.migrate’, test] in an individual app.
- And one thing more, if two of our apps has ecto and it dependency how can we make sure that an app that has another app (lets’ called it app2, with ecto), the ecto of app2 is also migrated while running the test of the top level app.
– There are some constraint that I am facing -
- When I add alias [“test”: [“ecto.create”, “ecto.migrate”, “test”]] in the root of my umbrella app like what is recommend here Umbrella app mix test migration alias error · Issue #1538 · elixir-ecto/ecto · GitHub. This thing when get executed, it try to boot up the supervision trees of other apps also (which I don’t want it to be booted, since I want to use --no-start and I want to boot them manually)
- Currently to make sure that ecto migrations of dependency app is migrated, run ecto.setup(create and migrate db of all apps, This is added as an alias in root umbrella mix.exs,) before I start any test. (But by doing this here, it will force all apps supervision trees (since this ecto.migrate makes supervision tree to be loaded also), which is one thing I dont want because I wants to test some of my apps with --no-start.
Most Liked
c-bik
I am in a similar situation. Looking for a tutorial of some sorts on how to run ecto tests on oracle adapter I am writing!
blisscs
I see what you meant there.
But by doing this, From what I understand we are not actually testing things that are written in Application Supervised GenServer cast or calls. And we are also assuming what is written in init function will have no effects in test environment. In general cases, I don’t think we can assume that.
This is what I think, In order to test init, and handle_cast, handle_call, handle_info calls of these Application supervised genservers, we should manually start application (spawn the application supervisor and test things).
These tests that I am referring to is the result of execution of init, handle_cast, handle_call and handle_info calls.
blisscs
I think I found the best way to do tests without using --no-start parameters and without using enable() function to check if I should enable that service in the test or not. By using this method it will guarantee that for each test, the application is always restarted.
The way to do this is pretty simple, We just need to make the ex_unit runs in synchronous mode and then we add code in to the tests’ setup block that stop the application and start the application again.
For example the code could look like below -
defmodule MyApp.ModuleTest do
use ExUnit, async: false
setup do
Application.stop(:my_app)
:ok = Application.start(:my_app)
end
.
.
.
end
The answer to this could be found in -
https://github.com/elixir-lang/elixir/issues/2929
and
I think there is one more question that I would like to ask for community best practice, is how to handle, the case where some of dependency apps (apps that are added inside other mix.exs app in umbrella app) also has ecto migrations to be migrated or seeds file to be seeded before the app test can be run. In my personal thinking, I just don’t think that running ecto migration on the root level of umbrella app before running test is the right way to do.
One of the reason why I think that I should not run migration and seeds on top level is that, and an app should not have dependency that maintain non temporal states(in here non temporal states mean the states that are persisted, or states that can not be discarded after some actions. Some of the actions could be running a test)
Generally when we test app with ecto, we usually configure ecto to run in sandbox for that app. but when this app is having dependencies of another apps that have ecto also, how can this app controls or has some knowledge of whether the sub apps that have ecto are running correctly and are running in the right mode and how can we be sure that after a test (test that contains creating and deleting records on the subapps)has finished running, the sub apps should discarded those changes after each test finishes)
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









