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

Bug: TimerHandle.when() isn't properly mocked? #3

Open
joshgoebel opened this issue Jun 17, 2022 · 0 comments
Open

Bug: TimerHandle.when() isn't properly mocked? #3

joshgoebel opened this issue Jun 17, 2022 · 0 comments

Comments

@joshgoebel
Copy link

joshgoebel commented Jun 17, 2022

Long story short

It seems that possibly TimerHandle#when isn't properly mocked? I'm trying to write a reschedulable timer, so that if you try to rescheduled it for shorter than the original request it fails, but you can easily extend it. This code was failing and adding some logging reveals very unexpected results around the timing values.

Description

Code in question:

def resuspend_keys(timeout):
    if is_suspended():
        loop = asyncio.get_event_loop()
        until_wake = _suspend_timer.when() - loop.time()
        if timeout < until_wake:
            return

    _suspend_timer.cancel()
    suspend_keys(timeout)

IE: find the currently planned execution time, how far into the future it is... and reschedule (or not depending)... but in logging both timer.when() and loop.time() I get output like:

(--) when 1945811.476378708
(--) loop time 2.0
(--) 1945809.476378708 until wake

It looks like loop time is being mocked as the tests moved thru time (I have a await asyncio.sleep(2)) but that the when() call is still returning some actual timestamp from the live running system.

If you need any additional details, please ask.

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

No branches or pull requests

1 participant