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

Rewrite remote_cache_tests.rs to mock the local runner #11474

Merged
merged 11 commits into from
Jan 20, 2021

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Jan 16, 2021

The tests were originally closer to integration tests, whereas we want high-quality, focused unit tests for both cache reads and cache writes.

This will allow us to do further mocking for the sake of testing speculation in #11429.

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Thanks Tom and Greg!

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
We need this for the cache write tests

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
We already have the atomic counter to keep track of local runs. It was adding unnecessary complexity

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano changed the title WIP: Rewrite remote_cache_tests.rs to mock the local runner Rewrite remote_cache_tests.rs to mock the local runner Jan 20, 2021
@Eric-Arellano Eric-Arellano marked this pull request as ready for review January 20, 2021 01:03
Copy link
Contributor Author

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

I don't expect the diff to be very insightful, given how much I rewrote these tests. Probably best to look at this test file as a completely new thing. (Although make_tree_from_directory and below is identical).

Thank you three for your help pair programming on this!!

Copy link
Contributor

@tdyas tdyas left a comment

Choose a reason for hiding this comment

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

lgtm plus some minor comments

#[derive(Clone)]
struct MockLocalCommandRunner {
result: Result<FallibleProcessResultWithPlatform, String>,
call_counter: Arc<Mutex<u32>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

More idiomatic is to use an atomic counter type like AtomicUsize.

Copy link
Contributor

Choose a reason for hiding this comment

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

More idiomatic is to use an atomic counter type like AtomicUsize.

I'm curious why you think it's more idiomatic to use an atomic type. My understanding is that the atomic types use some platform-specific overhead compared to the standard integer types, in order to provide thread safety, which we don't need in a test. So using an atomic type would add overhead for no particular gain here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Arc already has that same overhead give or take to implement its capital A IIUC. If threads aren't in play in tests the proof is dropping the Arc to an Rc and seeing if it compiles.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why you think it's more idiomatic to use an atomic type.

Just my impression that it is always nice to avoid a lock if possible, and atomic types let one do just that. This is test code so I'm not too concerned if this remains a Mutex for readability or other purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rc breaks because we store this on CommandRunner, which must implement Send.

I'll go with AtomicUsize instead of Mutex<u32> for clearer semantics.

Comment on lines +67 to +72
// NB: We bundle these into a struct to ensure they share the same lifetime.
struct StoreSetup {
pub store: Store,
pub store_dir: PathBuf,
pub cas: StubCAS,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice.

Comment on lines +87 to +89
10 * 1024 * 1024,
Duration::from_secs(1),
BackoffConfig::new(Duration::from_millis(10), 1.0, Duration::from_millis(10)).unwrap(),
Copy link
Contributor

Choose a reason for hiding this comment

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

remote_tests.rs has OVERALL_DEADLINE_SECS and RETRY_INTERVAL constants for some of these values. Maybe do something similar in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As in, share the constants across files? Or factor these up into constants? Imo the constants wouldn't be worth it very much because they're not used elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Share across files if you think it is worth it? My thought was DRY for test constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, it looks like the code to create a remote store is very similar across the two files. I think it could be worth factoring up, but probably as a second PR. This diff is already bad enough.

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano merged commit 600ae05 into pantsbuild:master Jan 20, 2021
@Eric-Arellano Eric-Arellano deleted the mock-local-runner branch January 20, 2021 17:58
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.

4 participants