Skip to content

Add +/- 1 second tolerance for clock adjustments#1481

Open
crlorentzen wants to merge 5 commits intopyca:mainfrom
crlorentzen:main
Open

Add +/- 1 second tolerance for clock adjustments#1481
crlorentzen wants to merge 5 commits intopyca:mainfrom
crlorentzen:main

Conversation

@crlorentzen
Copy link

I saw failure in my builds And decided why not add +/-1 second tolerance for clock adjustments, probably due to NTP synchronization and python rounding.

=================================== FAILURES ===================================
______________________ TestX509.test_gmtime_adj_notBefore ______________________
self = <tests.test_crypto.TestX509 object at 0xffffa4273210>
    @pytest.mark.flaky(reruns=2)
    def test_gmtime_adj_notBefore(self) -> None:
        """
        `X509.gmtime_adj_notBefore` changes the not-before timestamp to be the
        current time plus the number of seconds passed in.
        """
        cert = load_certificate(FILETYPE_PEM, self.pemData)
        not_before_min = utcnow().replace(microsecond=0) + timedelta(
            seconds=100
        )
        cert.gmtime_adj_notBefore(100)
        not_before_str = cert.get_notBefore()
        assert not_before_str is not None
        not_before = datetime.strptime(
            not_before_str.decode(), "%Y%m%d%H%M%SZ"
        )
        not_before_max = utcnow() + timedelta(seconds=100)
>       assert not_before_min <= not_before <= not_before_max
E       assert datetime.datetime(2026, 2, 23, 22, 6, 15) <= datetime.datetime(2026, 2, 23, 22, 6, 14) 

Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to just use 99 here, 101 below, and add a comment?

Copy link
Author

@crlorentzen crlorentzen Feb 25, 2026

Choose a reason for hiding this comment

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

Thinking about the purpose this test, which I assume is to ensure that gmtime_adj_notBefore() works. If no one objects I'll simplify to get time once, and make the min/max be +99,+101, and the adjustment +100 as originally defined.

@crlorentzen crlorentzen changed the title Add +/- 1 second tolerance for clock adjustmens Add +/- 1 second tolerance for clock adjustments Feb 25, 2026
@crlorentzen crlorentzen requested a review from mhils February 27, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants