Can #[serial]
usage assume test threads in a process are for the same crate?
#1577
Unanswered
EliahKagan
asked this question in
Q&A
Replies: 1 comment 3 replies
-
That's an interesting question, I never thought about it and wasn't aware that nextest may bundle up tests from different crates into the same process. The fact that it's not all breaking already probably tells us that |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How parallelism is implemented for testing, and when and how it uses multiple threads vs. multiple processes, varies across test runners, with
nextest
making more use of multiple processes. But I am not clear on what guarantees exist as part of the semantics of tests, nor on what assumptions are acceptable to make about how parallelism is achieved when running this project's test suite.Current use (and non-use) of
#[serial]
seems to assume that a test process that has multiple tests running in it on different threads has only tests for the same crate. When I added more tests in #1567 that use serial, I also made this assumption.This is to say that changing the current working directory and, in some cases, environment variables, seems to be well-accounted for with
#[serial]
, in terms of tests in the same crate that could interfere with one another, but not accounted for if tests across separate crates could run on separate threads in the same process.This is because, if I understand the documentation correctly:
#[serial]
only guarantees blocking to prevent running in the same process at the same time as another test that is also marked#[serial]
, or as tests that are marked#[parallel]
to allow them to run in parallel but not at the same time on the same thread as a#[serial]
test.#[serial]
to avoid data races while modifying global state used by code that is tested by various other tests in other crates, and#[parallel]
is only used ingix/tests/repository/shallow.rs
.cargo test
andcargo nextest
seem to set the current working directory to the root of the crate whenever--workspace
/--all
is used, which would be hard and probably impossible to do correctly while running tests from separate threads in the same process. But I'm not sure if this is a guaranteed behavior.My direct motivation for asking about this is noted in #1578 (see also #1580), but I am curious about in it general, and also to make sure I didn't introduce data races in the tests suite in #1567.
Beta Was this translation helpful? Give feedback.
All reactions