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

aya: use montonic SinceBoot for loaded_at #799

Closed
wants to merge 1 commit into from

Conversation

ajwerner
Copy link
Member

@ajwerner ajwerner commented Sep 28, 2023

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.

@netlify
Copy link

netlify bot commented Sep 28, 2023

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 02272cc
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/6515a0e882bc000008f72a42
😎 Deploy Preview https://deploy-preview-799--aya-rs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ajwerner ajwerner requested a review from tamird September 28, 2023 15:50
@mergify mergify bot added aya This is about aya (userspace) test A PR that improves test cases or CI labels Sep 28, 2023
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`.
@ajwerner ajwerner force-pushed the fix-flakey-test-loaded-at branch from e888291 to 02272cc Compare September 28, 2023 15:51
@mergify
Copy link

mergify bot commented Sep 28, 2023

Hey @alessandrod, this pull request changes the Aya Public API and requires your review.

@mergify mergify bot requested a review from alessandrod September 28, 2023 15:51
@mergify mergify bot added the api/needs-review Makes an API change that needs review label Sep 28, 2023
Copy link
Member

@tamird tamird left a 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

Copy link
Member

@tamird tamird left a 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.

@ajwerner
Copy link
Member Author

This doesn't seem worth the API churn. Will deflake with retries

@ajwerner ajwerner closed this Sep 28, 2023
@ajwerner ajwerner deleted the fix-flakey-test-loaded-at branch September 28, 2023 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api/needs-review Makes an API change that needs review aya This is about aya (userspace) test A PR that improves test cases or CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants