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

Update integration test to lower runtimes #883

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

simonsan
Copy link

@simonsan simonsan commented May 9, 2023

Does this have any downsides? It should speed up the integration tests overall?

could also help with #832

related: iqlusioninc/abscissa#845

@@ -26,9 +26,9 @@ static ADVISORY_DB_DIR: Lazy<TempDir> = Lazy::new(|| TempDir::new().unwrap());
/// be multithreaded invocations as `cargo test` executes tests in
/// parallel by default.
pub static RUNNER: Lazy<CmdRunner> = Lazy::new(|| {
let mut runner = CmdRunner::default();
let mut runner = CmdRunner::new(env!("CARGO_BIN_EXE_CARGO_AUDIT"));
Copy link
Member

Choose a reason for hiding this comment

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

What is this environment variable?

Copy link
Member

Choose a reason for hiding this comment

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

Seems it's breaking the tests...

error: environment variable `CARGO_BIN_EXE_CARGO_AUDIT` not defined at compile time

Copy link
Member

@Shnatsel Shnatsel May 9, 2023

Choose a reason for hiding this comment

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

It seems this should be using std::env::var_os instead of env!.

I doubt this is going to be any faster, but I'd be happy to be proven wrong.

Copy link
Member

Choose a reason for hiding this comment

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

And what's it supposed to do if that returns None?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@Shnatsel Shnatsel May 9, 2023

Choose a reason for hiding this comment

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

Nevermind, I got it all wrong. It should be env!("CARGO_BIN_EXE_cargo-audit")

Copy link
Author

@simonsan simonsan May 9, 2023

Choose a reason for hiding this comment

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

Yeah, my mistake. I could only try it with a tool that didn't have a hyphen in its name, so I was unsure how it would be called. But CARGO_BIN_EXE_cargo-audit or I guess CARGO_BIN_EXE_CARGO-AUDIT should be working now.

Copy link
Author

Choose a reason for hiding this comment

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

I doubt this is going to be any faster, but I'd be happy to be proven wrong.

before
after
diff

About a 90x times speed up in my case

Copy link
Author

@simonsan simonsan May 9, 2023

Choose a reason for hiding this comment

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

I haven't investigated exactly why that is, but a first guess seemed like my runtime was long because each stage was cloning RUNNER, and was rerunning cargo run -- each time. So only the overhead of that was 10s on my machine (Win11) adding up for each test.

Test is here:
https://github.com/simonsan/rustic/blob/refactor/tests/backup_restore.rs#L31

So my understanding was, if I would use the binary path directly, as that shouldn't recompile anything in any case, it should be circumventing that.

@Shnatsel
Copy link
Member

Shnatsel commented May 9, 2023

TL;DR: this is a worthwhile change, but I'd like to see it on the framework level (i.e. in abscissa) rather than fix up every user individually.

I've compared this against the main branch, measuring the second run of the tests (once the crates.io index cloning is done, which takes up the vast majority of the time), and it takes 50 seconds regardless of these changes.

With an up-to-date crates.io index, running cargo clean; cargo test --release --all-features --no-run and then measuring cargo test --release --all-features shows the new approach to be faster, because cargo run is invoked without --release and genuinely needs compile the debug build instead of using the release build that's already been compiled.

Contrary to @simonsan's suspicion, the compilation is performed exactly once, and cached after that. There's no recurring compilation assuming the Cargo cache works properly.

@simonsan
Copy link
Author

simonsan commented May 9, 2023

Before:

Commit: 0a33e37
Command: cargo nextest run -r --all-features --jobs 1
Comment: --jobs 1 because I had several semaphore/mutex and alloc issues with more than 2

Windows 11:
2023-05-09 21_37_47-Update integration test to lower runtimes by simonsan · Pull Request #883 · rust

Errors:
2023-05-09 22_19_52-Update integration test to lower runtimes by simonsan · Pull Request #883 · rust

After:

Command: cargo nextest run -r --all-features --jobs 1
2023-05-09 22_16_30-WDADesktopService

Command: cargo nextest run -r --all-features (~ jobs == 48)
2023-05-09 22_17_17-WDADesktopService

@simonsan
Copy link
Author

simonsan commented May 9, 2023

It actually seems like there is something wrong with the command runner and the Mutex. Maybe worth to investigate. I had several cmd mutex poisened errors when running tests with the default configuration of CmdRunner for rustic in the beginning.

@tarcieri
Copy link
Member

I had several cmd mutex poisened errors when running tests with the default configuration of CmdRunner for rustic in the beginning.

This will occur if a test fails while the mutex is held.

It should probably use panic::catch_unwind to prevent that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants