-
Notifications
You must be signed in to change notification settings - Fork 27
Fix cargo always treating nss crate as dirty #1042
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
base: main
Are you sure you want to change the base?
Conversation
969a327
to
2a47fd8
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1042 +/- ##
==========================================
+ Coverage 88.00% 88.04% +0.04%
==========================================
Files 85 85
Lines 6026 6039 +13
Branches 111 111
==========================================
+ Hits 5303 5317 +14
- Misses 663 666 +3
+ Partials 60 56 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
e2e27bc
to
dfd11fb
Compare
internal/testutils/rust.go
Outdated
// Note that for developing purposes and avoiding keeping building the rust program dependencies, | ||
// TEST_RUST_TARGET environment variable can be set to an absolute path to keep iterative | ||
// build artifacts. | ||
target := os.Getenv("TEST_RUST_TARGET") | ||
if target == "" { | ||
target = t.TempDir() | ||
} | ||
// Store the build artifacts in a common temp directory, so that they can be reused between tests. | ||
target := filepath.Join(os.TempDir(), "authd-tests-rust-build-artifacts") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@3v1n0 I would like to avoid re-building Rust dependencies by default, because I keep forgetting to set TEST_RUST_TARGET
when I run the tests. Do you see any cases where we shouldn't re-use build artifacts between tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the tests use different library builds, as per different features.
For example, SSH tests use different flags compared to the NSS library, and doing this we may end up creating problems between them (races as one library may being rebuilt while used).
One thing you can do is adding to the the target
path the features too, so that it will be unique.
Ideally I still would like to cleanup the path by default though, unless requested by the user, as leaving artifacts around is not nice in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the tests use different library builds, as per different features.
For example, SSH tests use different flags compared to the NSS library, and doing this we may end up creating problems between them (races as one library may being rebuilt while used).
cargo is smart enough to rebuild the affected artifacts when different features are selected. You can try running
cargo build --verbose --features integration_tests,custom_socket
in the authd repo and afterwards
cargo build --verbose --features integration_tests
you should see:
Dirty nss v0.1.0 (/home/[email protected]/projects/authd/nss): the list of features changed
Compiling nss v0.1.0 (/home/[email protected]/projects/authd/nss)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally I still would like to cleanup the path by default though, unless requested by the user, as leaving artifacts around is not nice in general.
As a user of this test, I very much prefer a few MB of artifacts lying around in /tmp over having to wait ~30s longer each time I run one of the affected tests, so I'm in favor of keeping the artifacts by default. We could add an environment variable to delete them if you think that's useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cargo is smart enough to rebuild the affected artifacts when different features are selected.
Sure, I'm aware of it, but we should not use the same build directory for different artifacts, no?
Otherwise we may have a test using features that another test is concurrently not in the need for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, now I get what you mean. I think we could avoid that by:
- Ensuring that only one build runs at a time, and
- Copying the resulting
.so
to a directory that includes the features and other relevant options in its name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in commit tests: Avoid races when building/using the NSS library
6c238af
to
18842d4
Compare
d0e51b1
to
1c1422d
Compare
1c1422d
to
d137268
Compare
internal/testutils/rust.go
Outdated
// Store the build artifacts in a common temp directory, so that they can be reused between tests. | ||
target := filepath.Join(os.TempDir(), "authd-tests-rust-build-artifacts") | ||
if v := os.Getenv("TEST_RUST_TARGET"); v != "" { | ||
target = v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target = v | |
target := os.Getenv("TEST_RUST_TARGET") | |
if target == "" { | |
target = filepath.Join(os.TempDir(), "authd-tests-rust-build-artifacts") |
Otherwise we create a dir for no eason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
d137268
to
0609f97
Compare
The $HOME environment variable wasn't set in the environment which the vhs command runs in, resulting in chromium being downloaded to `.cache/rod` in the current working directory, which is a temporary directory. In effect, chromium was being downloaded each time a test using vhs was executed, which made the test take ~1m longer.
Rebuilding the NSS library takes an unexpectedly long time, even if the code hasn't changed. Let's print the output of the cargo build command to get a better picture of what's going on.
I couldn't figure out exactly why, but `cargo build` always treated the nss crate as dirty and re-compiled it even when nothing changed in between two runs: cargo build --verbose [...] Dirty nss v0.1.0 (/home/user/projects/authd/nss): the file `nss/..` has changed (1756139002.017575102s, 2s after last build at 1756139000.627582074s) Compiling nss v0.1.0 (/home/user/projects/authd/nss) Using "../internal/proto" instead of "../" as the includes directory in the compile_protos call fixes that.
Now that the issue that the library was rebuilt each time has been solved, we don't the verbose output anymore.
Speeds up the tests if the developer did not set TEST_RUST_TARGET in the test environment.
* Lock the target directory to avoid multiple tests running in parallel trying to build the library at the same time (possibly with different set of features or other options). * Copy the resulting library to a temporary directory only used by the current test, to allow other tests to reuse the target directory (so that they don't have to rebuild it from scratch).
0609f97
to
46793c9
Compare
I couldn't figure out exactly why, but
cargo build
always treated the nss crate as dirty and re-compiled it even when nothing changed in between two runs:Using
"../internal/proto"
instead of"../"
as the includes directory in thecompile_protos
call fixes that.