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

Replace test-invocation-variants.sh with cargo test #215

Merged
merged 8 commits into from
Dec 1, 2022

Conversation

Enselic
Copy link
Owner

@Enselic Enselic commented Nov 24, 2022

This makes ./scripts/run-ci-locally.sh run in ~10s instead of ~12s for me.

It also significantly simplifies the testing infrastructure.

@Enselic Enselic added the category-exclude Will be excluded from the auto-generated release notes. label Nov 24, 2022
@Enselic Enselic changed the title Replace test-invocation-variants.sh tests with proper cargo test tests Replace test-invocation-variants.sh with cargo test Nov 24, 2022
@Enselic Enselic force-pushed the rm-test-invocation-variants.sh branch from 081dd3f to 446faec Compare November 24, 2022 18:56
@Enselic Enselic force-pushed the rm-test-invocation-variants.sh branch from 446faec to 90218ee Compare November 24, 2022 19:30
This makes `scripts/run-ci-locally.sh` run in 10s instead of 12s for me.

It also significantly simplifies the testing setup.
@Enselic Enselic force-pushed the rm-test-invocation-variants.sh branch from 90218ee to 7fdb404 Compare November 24, 2022 19:40
@Enselic
Copy link
Owner Author

Enselic commented Nov 24, 2022

I think the problem we are seeing is rust-lang/rustup#988

We might need to handle rustup concurrency ourselves somehow :(
Or simply install toolchains as a pre-cargo test step (:vomiting_face: )

An adventure for some other day...

@Enselic Enselic marked this pull request as draft November 24, 2022 19:47
Comment on lines 863 to 867
let mut cmd = Command::from_std(std::process::Command::new("cargo"));
if let Some(toolchain) = toolchain {
cmd.arg(format!("+{}", toolchain));
}
cmd.arg("public-api");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to do the same thing as here:

let mut cmd = std::process::Command::new("rustup");
cmd.args(["run", toolchain, "cargo"]);
cmd

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yes that might work, but then the test would not do what regular users do, which IMHO is quite important.

After thinking some more about how to approach this short term, I think requiring toolchains to be pre-installed before tests run is reasonable, and provide a helper script to do so. I'd really like to get this PR merge sooner rather than later, because otherwise the risk of conflicts is high, and I see it as a significant improvement.

If I just can get this to work in Windows now...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I should have made myself clear.

The code works around rust-lang/rustup#3036, which is this exact issue (however the error message seems to have changed a bit)

error: no such subcommand: `+beta`
    
    Cargo does not handle `+toolchain` directives.
    Did you mean to invoke `cargo` through `rustup` instead?

Copy link
Owner Author

@Enselic Enselic Nov 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a ton for clarifying. I had completely forgotten about that bug. You saved me a lot of debugging time.

I've pushed a fix now, and CI is green.

I can think of many follow-up improvements to this PR, but let's get this merged before we improve on it further.

One idea:
Why don't we put the helper to install toolchains in e.g. rustdoc-json crate, and then install the necessary toolchain automatically for users (if it is missing) during regular cargo public-api use?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not expect rustdoc-json to have rustup stuff in it. I'm definitely myself against installing the toolchain automatically via a rustup toolchain install but I see the value 👍🏼

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting viewpoint! Let's break it down to a specific example. Consider a user that has stable installed but not nightly. Then that user does cargo install cargo-public-api and then cargo public-api.

In this case, I bet that say 95% of users want us to do the work to install nightly for them. Otherwise the tool that they just downloaded is useless!

The 5% that do NOT want us to install nightly for them can just Ctrl-C and stop the process.

This is a classic interaction design rule actually. Don't let the 5% ruin the experience for the other 95% :)

I am of course happy to keep discussing this. There might very well be some aspect here I am not thinking about. Meanwhile, I have created a new rustup-toolchain crate: https://crates.io/crates/rustup-toolchain, which we'll need it regardless of if we install nightly by default or allow users to opt-in. I'll wait with creating a PR for that though until we have landed this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I guess I'm that 5% :D

Copy link
Owner Author

@Enselic Enselic Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick experiment, but all tests started failing after uninstalling nightly toolchain, so I don't see me pursuing auto-install in the near future

For the record, prototype code at main...auto-install-toolchain

I mean, probably quite easy to make it work, but I don't consider this urgent or crucial, so I'll put it on hold for now

Which will install toolchains needed for tests. Long-term it will be
nice to get rid of this, but since this is a one-time thing, I think we
can live with it.

If a dev runs `cargo test` with missing toolchains, the dev will see
this error:

    thread 'warn_when_using_beta' panicked at '
    You must run

        ./scripts/install-toolchains-for-tests.sh

    before running tests. Or simply run

        ./scripts/run-ci-locally.sh

    to both install toolchains and run tests in one command.
    ', cargo-public-api/tests/../../test-utils/src/lib.rs:70:5
@Enselic Enselic force-pushed the rm-test-invocation-variants.sh branch from 9302261 to e1a3b4b Compare November 25, 2022 15:46
@Enselic
Copy link
Owner Author

Enselic commented Nov 25, 2022

Hmm interesting, we get the same error now. So probably we don't need ./scripts/install-toolchains-for-tests.sh. We just need the regular code to work on Windows.

Maybe time for me to buy a Windows license so I can debug this...

@Enselic Enselic force-pushed the rm-test-invocation-variants.sh branch from 8171531 to 7054ed9 Compare November 30, 2022 06:54
This reverts commit e1a3b4b.

Keep some of the changes to the README though.
Since a single test takes a very long time if it needs to install a
toolchain, I want there to be an indication of what is going on and why
the test is so slow.
@Enselic Enselic marked this pull request as ready for review November 30, 2022 18:02
@Enselic Enselic merged commit e990141 into main Dec 1, 2022
@Enselic Enselic deleted the rm-test-invocation-variants.sh branch December 1, 2022 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category-exclude Will be excluded from the auto-generated release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants