Serialize tests that need environment variables#1685
Merged
Conversation
NobodyXu
requested changes
Mar 8, 2026
NobodyXu
approved these changes
Mar 8, 2026
Contributor
NobodyXu
left a comment
There was a problem hiding this comment.
The two nits should not be blocking
Contributor
Co-authored-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>
Member
|
Rather than serialisation, could you |
Contributor
Author
Generally though, I'd rather have high complexity in tests and low complexity in the implementation (instead of having to support mocking). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One of the things that's been bugging me about our test suite for a while is that we modify the global environment with
std::env::set_varandstd::env::remove_varin a very ad-hoc fashion, including doing things like , or callingreset_env()at the top of every test.Instead, this PR introduces a
GlobalEnvstruct that takes a global lock, allows setting / removing variables only when that lock is held, and reverts the environment back to what it was once the test is done.Unfortunately, this does force us to serialize every test, but I don't see any other solution. If we wanted, we could use
cargo nextestin CI, see #1402, but let's handle that separately.This is important for #1682, where I change
Build::env, and thus we'll need some other way of consistently setting environment variables in tests, but I also imagine it'll be nice to have for testing things like CC's auto-TARGETsourcing.