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

cargo test --doc does not respect CARGO_BUILD_JOBS env variable #97551

Open
tmpolaczyk opened this issue May 30, 2022 · 2 comments
Open

cargo test --doc does not respect CARGO_BUILD_JOBS env variable #97551

tmpolaczyk opened this issue May 30, 2022 · 2 comments
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@tmpolaczyk
Copy link

I originally reported this issue in the cargo repo: rust-lang/cargo#10702 but I was told that "this behaviour is controlled by rustdoc".

Problem

I use a global variable CARGO_BUILD_JOBS=4 because the default configuration results in my machine running out of memory when compiling some rust projects. However recently I noticed that this fails when there are many doc tests in the project, because it looks like all the doc tests are compiled in parallel.

Steps

  1. Find some project with many doc tests
  2. export CARGO_BUILD_JOBS=1
  3. cargo test --doc
  4. In a separate terminal, run pidof rustc and notice how there are as multiple processes, instead of the expected 1.
  5. This results in the tests failing, in my case because the linker is killed because the system has run out of memory.

Possible Solution(s)

In my opinion the correct behavior is to respect CARGO_BUILD_JOBS when compiling the tests.

As a workaround, you can use

cargo test -- --test-threads 1

to limit the number of build jobs to 1, however this also affects normal tests, so running tests will be much slower.

Version

cargo 1.61.0 (a028ae4 2022-04-29)
release: 1.61.0
commit-hash: a028ae42fc1376571de836be702e840ca8e060c2
commit-date: 2022-04-29
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1m)
os: Ubuntu 22.04 (jammy) [64-bit]

Comments

@weihanglo provided helpful comments:

To my understanding, rustdoc collects each doctest and compiles them by invoking rustc on-the-fly1, and that is included as a part of test fn2, which will be executed by libtest.

That tells us why build.jobs (controls cargo-rustc jobserver) doesn't affect parallelism of doctest, but --test-threads does (controls parallelism of libtest).

@tmpolaczyk tmpolaczyk added the C-bug Category: This is a bug. label May 30, 2022
@Urgau
Copy link
Member

Urgau commented May 30, 2022

As I wrote here rust-lang/cargo#10702 (comment), I don't think this is a rustdoc issue at all because rustdoc has no knowledge of cargo and it's environment variables and shouldn't have any.

@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@fmease fmease added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. A-libtest Area: #[test] related C-discussion Category: Discussion or questions that doesn't represent real issues. and removed C-bug Category: This is a bug. needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. A-libtest Area: #[test] related labels Apr 17, 2024
@weihanglo
Copy link
Member

rust-lang/testing-devex-team#5 could be one solution to this, in the sense that Cargo controls test execution for doctests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants