Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better control of test-execution order #6266

Open
lukaslueg opened this issue Nov 5, 2018 · 3 comments
Open

Better control of test-execution order #6266

lukaslueg opened this issue Nov 5, 2018 · 3 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-test S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix

Comments

@lukaslueg
Copy link
Contributor

lukaslueg commented Nov 5, 2018

Cargo currently does not take too much care about what order tests are executed. cargo_test::compile_tests() places them in order of (PackageID, TargetKind, Name). We could do better than that by ordering test execution by

  1. If the test has failed before
  2. If the test has been executed at all
  3. (PackageID, TargetKind)
  4. The time it took the last time to execute this test, in descending order
  5. Name

This has some benefits:

  • Failing tests are executed first, without the need to stop cargo watch and filter the test we just broke.
  • Tests which have not been executed at all (due to fail-fast) are executed as soon as possible, so we get a least one reading
  • Slow tests are scheduled first, so their execution overlaps as long as possible, avoiding having just one or two slow tests be scheduled at the end and consuming just one cpu.

Notice that if the testsuite completes successfully, the ordering almost returns to current behaviour, with only latency-scheduling taking precedence over Name.

To do this, we'd need to persists some information to disk. We could do this by writing a "marker"-file somewhere in /target for every test (consider "target/testruns/test-hash(...)") where the files' ctime is the time the test were last started and the files' mtime is the time the tests were last completed successfully. We can reconstruct the above ordering from that.
Alternatively we serialize a single struct to disk.
Also notice that the ordering we derive from this information may be wrong or outdated (e.g. by changing test-bodies), yet this does not cause the testsuite to execute incorrectly as a whole and Is Only Wrong Once™

See also #10673

@alexcrichton alexcrichton added Command-test C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` labels Nov 5, 2018
@lukaslueg
Copy link
Contributor Author

Oh and I can probably implement this if so desired.

@epage
Copy link
Contributor

epage commented May 24, 2023

This would likely require changing the relationship between cargo and libtest which I plan to do for #5609.

With that said, I would recommend experimenting with the policy for this in cargo-nextest before we evaluate such a policy for cargo.

@epage epage added the S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix label May 24, 2023
@sanmai-NL
Copy link

Another value add: sometimes a user is involved in software based (scientific) experiments. While automated tests should not be dependent on their order of execution, ideally, sometimes you do see a certain order dependence with a certain phenomenon you investigate. For example, related to performance, efficiency, energy efficiency, or security. Being able to control execution order would be valuable in such use cases as well. In this context I now use cargo-nextest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-test S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix
Projects
Status: No status
Development

No branches or pull requests

4 participants