Skip to content

VSCode Test Explorer - unit test execution is slow/problematic because they run at the workspace level not crate #17470

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

Closed
duncanawoods opened this issue Jun 21, 2024 · 1 comment
Labels
A-test-explorer Issues related to the test explorer lsp extension and vscode test api C-bug Category: bug

Comments

@duncanawoods
Copy link

duncanawoods commented Jun 21, 2024

Invoking a single unit test from the Test Explorer or keyboard shortcut will build the entire workspace and tests are processed in every workspace member which causes several problems:

  • unit tests cannot run if any crate in a workspace does not compile even though they are not relevant dependencies
  • running a unit test builds unrelated crates on every/any code change
  • unit tests are referenced by their name within a crate which can collide between between workspace members
    • e.g. two clis in a workspace with a main.rs containing mod tests :: test_arg_parsing
    • this means the wrong test is run / results reported against the wrong test etc.
  • even without any code changes:
    • unit tests run much slower because the runner tries to run the test in every single workspace member
      • rust-analyzer takes multiple seconds to run a test that cargo test completes in milliseconds
    • there is excess message spam in the test output because it contains every warning/lint and build message from the entire workspace

Example test output trying to execute one unit test where rust-anlayzer tries to run a test in every single workspace member which I have anonymised as <crate>:

Running unittests src/main.rs (target/debug/deps/<crate>-d7d1af8a1ff77b91)
Running unittests src/main.rs (target/debug/deps/<crate>-8f1e321689784723)
Running unittests src/main.rs (target/debug/deps/<crate>-630fa9cd06696d27)
Running unittests src/main.rs (target/debug/deps/<crate>-94ccfaaf3259bc9c)
Running unittests src/main.rs (target/debug/deps/<crate>-03afafaad8d31312)
Running unittests src/lib.rs (target/debug/deps/<crate>-6ec99e8e97e196c7)
Running unittests src/lib.rs (target/debug/deps/<crate>-1294bbf4f9a3a681)
Running unittests src/main.rs (target/debug/deps/<crate>-a0bf89f18085b65e)
Running unittests src/main.rs (target/debug/deps/<crate>-c2d90a1bf651628e)
...
etc.
Doc-tests <crate>
Doc-tests <crate>
Doc-tests <crate>
Doc-tests <crate>
Doc-tests <crate>
Doc-tests <crate>
Doc-tests <crate>
...
etc.

@HKalbasi I can see this relates to your changes here:

#17056

I have a PR that behaves as I expect which is to run tests on the crate in which they are defined and not at the workspace root but I don't know if this will cause other issues.

@duncanawoods duncanawoods added the C-bug Category: bug label Jun 21, 2024
duncanawoods pushed a commit to duncanawoods/rust-analyzer that referenced this issue Jun 21, 2024
@roife roife added the A-test-explorer Issues related to the test explorer lsp extension and vscode test api label Jun 24, 2024
duncanawoods pushed a commit to duncanawoods/rust-analyzer that referenced this issue Jul 22, 2024
duncanawoods pushed a commit to duncanawoods/rust-analyzer that referenced this issue Jul 27, 2024
duncanawoods pushed a commit to duncanawoods/rust-analyzer that referenced this issue Jul 27, 2024
duncanawoods pushed a commit to duncanawoods/rust-analyzer that referenced this issue Jul 28, 2024
duncanawoods pushed a commit to duncanawoods/rust-analyzer that referenced this issue Jul 28, 2024
duncanawoods pushed a commit to duncanawoods/rust-analyzer that referenced this issue Jul 28, 2024
bors added a commit that referenced this issue Jul 28, 2024
#17470 - run unit tests at the crate level not workspace

For #17470

Use the test path to identify a package in the workspace and run the unit test there instead of at the workspace.
lnicola pushed a commit to lnicola/rust that referenced this issue Jul 28, 2024
rust-lang#17470 - run unit tests at the crate level not workspace

For rust-lang/rust-analyzer#17470

Use the test path to identify a package in the workspace and run the unit test there instead of at the workspace.
@lnicola
Copy link
Member

lnicola commented Jul 29, 2024

Fixed in #17472.

@lnicola lnicola closed this as completed Jul 29, 2024
RalfJung pushed a commit to RalfJung/rust that referenced this issue Aug 1, 2024
rust-lang#17470 - run unit tests at the crate level not workspace

For rust-lang/rust-analyzer#17470

Use the test path to identify a package in the workspace and run the unit test there instead of at the workspace.
bors added a commit that referenced this issue Aug 25, 2024
fix: add extra_test_bin_args to test explorer test runner

`@HKalbasi` I thought I included this in #17470 but it appears not so I have created a new issue #17959 for this fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-test-explorer Issues related to the test explorer lsp extension and vscode test api C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants