-
Notifications
You must be signed in to change notification settings - Fork 298
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
aya: use montonic SinceBoot for loaded_at #799
Conversation
✅ Deploy Preview for aya-rs-docs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
This commit was written to deflake test_loaded_at. The flakiness is due to the lack of monotonicity in SystemTime clock calculations. See https://github.com/aya-rs/aya/actions/runs/6340369670/job/17221591723. This PR addresses that problem by introducing a wrapper type to encapsulate the monotonically increasing duration since boot, `SinceBoot`. This type has a method `into_system_time()` to convert it into a `SystemTime`.
e888291
to
02272cc
Compare
Hey @alessandrod, this pull request changes the Aya Public API and requires your review. |
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.
Reviewed 5 of 5 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @ajwerner and @alessandrod)
-- commits
line 5 at r1:
"calculations" is wrong - this doesn't have to do with calculations, it has to do with reading wall time more than once.
-- commits
line 8 at r2:
s/PR/commit/ or just drop the word.
consider doing the same in the previous paragraph - drop the noun
aya/src/time.rs
line 7 at r2 (raw file):
/// A timestamp relative to the system boot time. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct SinceBoot(Duration);
should the nomenclature be something like Instant?
aya/src/time.rs
line 10 at r2 (raw file):
impl SinceBoot { /// The current SinceBoot.
mirror the comment on https://doc.rust-lang.org/stable/std/time/struct.SystemTime.html#method.now?
aya/src/time.rs
line 12 at r2 (raw file):
/// The current SinceBoot. /// /// Note that these calls will be monotonic.
not appropriate to document CLOCK_BOOTTIME, and "these calls" is not the right subject? also, this is used in testing only -- can we perhaps move it there?
aya/src/time.rs
line 19 at r2 (raw file):
/// Converts the timestamp to a `SystemTime`. /// /// Note that this will not be robust to changes in the system clock, and thus these
I don't think we should document the semantics of ST here. it's all discussed at length: https://doc.rust-lang.org/stable/std/time/struct.SystemTime.html#
aya/src/time.rs
line 26 at r2 (raw file):
} pub(crate) fn from_nanos(nanos: u64) -> Self {
maybe just new
and take a duration? no reason to make the reader read "nanos" 3 times.
aya/src/time.rs
line 34 at r2 (raw file):
let since_boot = get_time(libc::CLOCK_BOOTTIME); let since_epoch = get_time(libc::CLOCK_REALTIME); UNIX_EPOCH + since_epoch - since_boot
this has only one caller, and when you combine it with the caller this is just SystemTime::now() + (self - Self::now())
, I think?
aya/src/time.rs
line 55 at r2 (raw file):
#[test] fn test_since_boot_now_into_system_near_system_time() { let since_boot = SinceBoot::now().into_system();
let's avoid reading the real clock more than once -- as that is the source of flakes
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.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @ajwerner and @alessandrod)
aya/src/time.rs
line 34 at r2 (raw file):
Previously, tamird (Tamir Duberstein) wrote…
this has only one caller, and when you combine it with the caller this is just
SystemTime::now() + (self - Self::now())
, I think?
edit: i think this should be SystemTime::now() - (Self::now() - self)
to avoid a negative duration.
This doesn't seem worth the API churn. Will deflake with retries |
This commit was written to deflake test_loaded_at. The flakiness is due
to the lack of monotonicity in SystemTime clock calculations. See
https://github.com/aya-rs/aya/actions/runs/6340369670/job/17221591723.
This PR addresses that problem by introducing a wrapper type to
encapsulate the monotonically increasing duration since boot,
SinceBoot
. This type has a methodinto_system_time()
to convert itinto a
SystemTime
.