Fl4m3Ph03n1x

Fl4m3Ph03n1x

Run umbrella project tests sequencially

Background

I have an umbrella project with several apps.
Some of these apps have runtime libraries as dependencies, some apps depend on others and so on.

My objective is, when on the root level of the project, to run all the tests for all the child apps using mix test.

Problem

When on the root level, running mix test will run the tests of all child apps. However this happens in a parallel way, from what I can see.

This is a problem because some dependencies between child apps are shared. Consequently some apps succeed, and others fail, thus breaking my CI/CD pipeline.

This is not a problem at all if I run the tests for each child separately, but alas, I want to be able to use mix test from the root level.

What I tried

So, my initial approach was create an alias that replaces mix test with my own command:

defp aliases do
    [
      test: ["cmd --app app1 mix test --color", "cmd --app app2 mix test --color"]
    ]
  end

This will work and will execute the tests of the child apps sequentially.

Questions

However this solution is hard-coded and not very flexible. If tomorrow I remove an app, the command will break. If I add a new one, the command won’t run its tests unless I remember to edit it.

I wonder if there is a better way of doing this that would be:

  • flexible instead of hard-coded
  • run the tests sequentially instead of parallel

Marked As Solved

Fl4m3Ph03n1x

Fl4m3Ph03n1x

defp aliases do
  child_tests =
      Path.wildcard("apps/*")
      |> Enum.map(&String.replace(&1, "apps/", ""))
      |> Enum.map(fn app -> "cmd --app #{app} mix test --color" end)

    [test: child_tests]
end

This did the trick. Thanks :smiley:

Also Liked

LostKobrakai

LostKobrakai

So the proper solution would be removing any global state from your testsuites, which makes mix test fail as it does.

But also mix.exs is elixir – you can use code to define the alias:

test = 
  Mix.Project.apps_paths()
  |> Keyword.keys()
  |> Enum.map(fn app -> "cmd --app #{app} mix test --color" end)

[test: test]
LostKobrakai

LostKobrakai

Path.wildcard("apps/*) would likely do fine as well :sweat_smile:

Where Next?

Popular in Questions Top

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
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement