Skip to content

libtest should set RUST_TEST_THREADS environment variable #74845

Open

Description

@nbaksalyar

We can configure the test runner concurrency by using either the --test-threads parameter, or by setting the environment variable RUST_TEST_THREADS:

let concurrency = opts.test_threads.unwrap_or_else(get_concurrency);

As some tests might need to read the current concurrency configuration, the only way to do this currently is by reading the said environment variable. However, if we use --test-threads, this information is not passed further to tests. I think this behaviour is a bit inconsistent and the env var should be always set to the actual value, e.g.:

let concurrency = opts.test_threads.unwrap_or_else(get_concurrency);
env::set_var("RUST_TEST_THREADS", concurrency.to_string());

Activity

  1. added
    A-libtestArea: `#[test]` / the `test` library
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    on Jul 27, 2020
  2. bjorn3 commented on Jul 27, 2020

    @bjorn3
    Member

    I think the name would be ambiguous when using an external process to run the tests (used for -Cpanic=abort only targets) It could refer to the total amount of concurrenr threads or the total amount of threads in the current process (1)

  3. added a commit that references this issue on Aug 11, 2025
  4. added a commit that references this issue on Aug 12, 2025
  5. added 3 commits that reference this issue on Aug 12, 2025
  6. added a commit that references this issue on Aug 13, 2025
  7. added a commit that references this issue on Aug 13, 2025
  8. added a commit that references this issue on Aug 18, 2025
  9. epage commented on Sep 5, 2025

    @epage
    Contributor

    In #145269, we deprecated RUST_TEST_* environment variables so this would be less about consolidating information to one place / consistency of information but more of providing a mechanism to tell tests what the concurrency level is.

    One challenge with tests reading the number of available threads is that is meant to be about constraining resources and the test runner itself is using up all of those resources. Instead, it seems like we'd need tests to acquire and release these resources from the test runner. I feel like us providing our own API for this is unlikely to happen and would end up being left to custom test harnesses. We could defer to jobserver (#48532) but that might be a bit more complicated.

    It would help to know what the use case is for why a test knowing the number of threads would matter.

  10. added
    S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.
    on Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryC-feature-requestCategory: A feature request, i.e: not implemented / a PR.S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions