NobbZ

NobbZ

Is there a way to predetermine which tests and why would be run on `mix test --stale`

I’m currently in the process of taking over a very large codebase in my new job and already did my first simple changes within a day ago or two.

The problem is, the way it is now, the tests are mostly running as async: false and take a whole 10 to 15 minutes when running the full suite.

The changes I made have been covered by roughly 10 tests, which could be ran within a split second, still due to a lot of deps which I still have to debug/analyze, hundreds or thousands of tests are ran, which take also 5 to 10 minutes per iteration.

Is there an easy way, to discover why these tests are ran? How they depend on the changed module? mix xref --sink does not tell anything about the tests.

Most Liked

dimitarvp

dimitarvp

I always wanted to get more proficient in mix xref but sadly I admit I still haven’t. I’ve scoped some threads in the past where people had partial and small success untangling some dependencies but IMO right now you have a better chance asking colleagues and eye-balling.

Sorry I can’t be of more help. :confused:

Still, you can start off with mix xref graph --label compile-connected; this seems to (partially) address runtime dependencies, not only compile-time ones.

A super heavy gun would be to use https://comby.dev for finding references in code.

Recently I used this to be able to track and collect all functions (of a single module) used in a project:

$1 = "ex" # Elixir
$2 = "Api"

comby -matcher ".$1" -match-only -json-lines "$2:[~.|::|->]:[fn](:[_])" '' | jq '.matches[].environment[] | select(.variable == "fn")' | jq -r '.value' | sort | uniq

Or, to give an example (since the above is a wrapper script I made):

comby -matcher ".ex" -match-only -json-lines "Api:[~.|::|->]:[fn](:[_])" '' | jq '.matches[].environment[] | select(.variable == "fn")' | jq -r '.value' | sort | uniq

I also used it by doing cd $project/test first. This helped me establish which functions I should make a behaviour out of because I wanted to mock a module with Mox (since its tests currently directly hit a real production API).

Nezteb

Nezteb

Aaaaand, merged!

dimitarvp

dimitarvp

Reading through mix help test’s section on --stale:

## The --stale option

The --stale command line option attempts to run only the test files which
reference modules that have changed since the last time you ran this task with
--stale.

The first time this task is run with --stale, all tests are run and a manifest
is generated. On subsequent runs, a test file is marked "stale" if any modules
it references (and any modules those modules reference, recursively) were
modified since the last run with --stale. A test file is also marked "stale" if
it has been changed since the last run with --stale.

The --stale option is extremely useful for software iteration, allowing you to
run only the relevant tests as you perform changes to the codebase.

…it seems you have to be only using mix test --stale for the “only re-run tests whose tested modules (or the tests themselves) have changed” check to work.

So you probably have to endure one full run first.

Additionally, you can tag your tests with @mytag true and then only run them with mix test --only mytag?

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43657 311
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31194 112
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52774 488
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement