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

Seed management to improve reproducibility #1380

Merged
merged 2 commits into from
Oct 28, 2024

Conversation

andyleiserson
Copy link
Collaborator

Changes to tests and test infrastructure to be able to reproduce test runs from a seed.

This just updates one example of each kind of test I could think of to demonstrate how to achieve reproducibility. There are still many other tests that would need to be updated to match.

Fixes #1321

Comment on lines +504 to +516
)
(
len in Just(len),
tv_bits in Just(tv_bits),
inputs in prop::collection::vec(prop::array::uniform(0u32..1 << tv_bits), len),
)
-> AggregatePropTestInputs {
let mut rng = StdRng::seed_from_u64(seed);
let mut expected = vec![0; PROP_BUCKETS];
let inputs = repeat_with(|| {
let row: [u32; PROP_BUCKETS] = array::from_fn(|_| rng.gen_range(0..1 << tv_bits));
for row in &inputs {
for (exp, val) in expected.iter_mut().zip(row) {
*exp = min(*exp + val, (1 << PropHistogramValue::BITS) - 1);
}
row
})
.take(len)
.collect();
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These changes are not essential to this PR, but it seemed clearer not to have two different seeds, and using proptest for input generation enables using its other capabilities like shrinking.

// iterations (or to make the API use `Fn` to match the shuttle version), the
// simplest strategy might be to seed per-iteration RNGs from a primary RNG, like
// `TestWorld::rng`.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

@@ -190,6 +200,13 @@ impl Default for TestWorld {
}
}

impl TestWorld {
#[must_use]
pub fn with_seed(seed: u64) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Default values for generic parameters is a blessing and a curse.

impl TestWorld<NotSharded> that exists on the line 266 is probably a better place for this fn.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is there a reason to implement Default only for TestWorld<NotSharded>?

Copy link
Collaborator

Choose a reason for hiding this comment

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

backward compatibility was the only one - I didn't want to change a bunch of non-sharded tests when introducing the in-memory sharding infrastructure

@akoshelev
Copy link
Collaborator

Thank you for making this change @andyleiserson, we are getting closer to fully reproducible tests with it

Copy link

codecov bot commented Oct 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.57%. Comparing base (57e2c63) to head (5bdb2b5).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1380      +/-   ##
==========================================
+ Coverage   93.54%   93.57%   +0.03%     
==========================================
  Files         222      223       +1     
  Lines       36986    37117     +131     
==========================================
+ Hits        34600    34734     +134     
+ Misses       2386     2383       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andyleiserson andyleiserson merged commit f843aa6 into private-attribution:main Oct 28, 2024
12 checks passed
@andyleiserson andyleiserson deleted the rng branch October 28, 2024 21:47
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.

Ensure TestWorld seed is propagated to all RNGs
2 participants