Fl4m3Ph03n1x

Fl4m3Ph03n1x

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

Showing Posts 1 to 4

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]
Fl4m3Ph03n1x

Fl4m3Ph03n1x OP

Unfortunately this won’t work, as Mix.Project.app_paths() is not resolved at compile time. So when I run the command, line 2 gets a nil instead of a keyword list and the whole thing crashes.

I have also tried Mix.Project.config(), which does work at compile time, but sadly it has no information about child apps.

LostKobrakai

LostKobrakai

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

Fl4m3Ph03n1x

Fl4m3Ph03n1x OP

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:

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
widianto
I think I’ve found a small improvement I could contribute to <%= web_namespace %>.CoreComponents (installer/templates/phx_web/compo...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews