Skip to content

Implement generator for Duration#133

Open
echoumcp1 wants to merge 4 commits intohegeldev:mainfrom
echoumcp1:echoumcp1/impl-duration
Open

Implement generator for Duration#133
echoumcp1 wants to merge 4 commits intohegeldev:mainfrom
echoumcp1:echoumcp1/impl-duration

Conversation

@echoumcp1
Copy link
Copy Markdown
Contributor

@echoumcp1 echoumcp1 commented Mar 26, 2026

#118

Debating between the current implementation for durations() or effectively making it integers::<u64>().map(Duration::from_nanos) with maybe a wrapper for the Duration-typed bounds but no preference either way.

@echoumcp1 echoumcp1 marked this pull request as ready for review March 26, 2026 20:21
/// ```
pub fn instants() -> InstantGenerator {
InstantGenerator {
base: Instant::now(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the base being now is a bad idea, because it means you get a different instant each time the test replays, so now your tests are possibly flaky. I'd rather have a fixed base (e.g. time zero, which is presumably the unix epoch?) and let the user set it with a base(Instant) method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Instant is intentionally opaque and Instant::now() is the only way to construct an Instant. If the goal is to generate arbitrary points in time then I think SystemTime is what we need.

e.g.
SystemTime::UNIX_EPOCH + std::time::Duration::from_nanoseconds(828273)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Record of conversation we had on zulip: It does indeed seem to be impossible to get a fixed Instant in rust (which is for the record insane). I suggested that we can at least fix the instant once at test start time by having a global (mutex locked) base set to Instant::now. It gets us reproducibility within a single process, and usually gets us reproducibility across processes unless something bad is happening.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this does in fact seem insane and I would like to think hard about the right thing to do here. @echoumcp1 I'd be happy to get Duration in in a separate PR while we decide on Instant

@echoumcp1 echoumcp1 changed the title Implement generators for Duration and Instant Implement generator for Duration Mar 27, 2026
@echoumcp1 echoumcp1 requested a review from Liam-DeVoe March 27, 2026 17:22
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.

3 participants