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?

NobbZ

NobbZ

I endured the first run, and still subsequent stale runs have taken that long, as there is some coupling that is probably not necessary.

I admit, the module I changed was part of user authentication and therefore probably affects all somehow web related tests, though in the case of not so obvious things, are there tools to debug that?

Before I wade through all web related tests and manually check if they require authentication and mock it out, what tools do I have at hand to verify that before hands? Such that I can contentrate on those tests first, that would give the biggest gain?

At the same time, such an analyzis might give additional insights into unwanted coupling which might be discovered “accidentally” by such --stale test runs.

Nezteb

Nezteb

Random bump, but here’s a GitHub gist post you might like about removing transitive dependencies using mix xref: deps.md · GitHub

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
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
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
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

Other popular topics Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement