blisscs

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-start in 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 -

  1. 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)
  2. 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

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

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

blisscs

Hi @zacksiri, @c-bik

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)

Where Next?

Popular in Discussions Top

vans163
So useless benchmarks aside, Its possible to write a webserver that can serve 300k requests per second (perhaps more with optimizations)....
New
Donovan
Hello everyone, I’m so glad to have discovered this awesome community. Thanks for creating it! This is my second post, and apologies for...
New
Ankhers
Just a little information upfront. Generally speaking, if I feel like I need to either break a pipe chain or use an anonymous function in...
New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 19652 166
New
AstonJ
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
Crowdhailer
I’ve been hearing much about the new formatter and it’s something I have been keen to try. I find examples buy far the most illuminating...
248 19327 150
New
CharlesO
Erlang :list.nth simple, but 1 - based nth(1, [H|_]) -> H; nth(N, [_|T]) when N > 1 -> nth(N - 1, T). Elixir Enum.at … coo...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
griffinbyatt
Sobelow Sobelow is a security-focused static analysis tool for the Phoenix framework. For security researchers, it is a useful tool for g...
New
sashaafm
Piggy backing a bit on @dvcrn topic BEAM optimization for functions with static return type?, I’ve been trying to understand in a deeper ...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29603 241
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
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
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
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

We're in Beta

About us Mission Statement