Skip to content

Mock clock cannot jump into the past, but uses seconds_to_next_deadline which can ! #1190

Closed
@touilleMan

Description

@touilleMan

When using hypothesis with the mock_clock fixture, I sometime end up with a raise ValueError("time can't go backwards")

The thing is we have MockClock._autojumper doing this:

statistics = _core.current_statistics()
jump = statistics.seconds_to_next_deadline
if jump < inf:
self.jump(jump)

However according to current_statisticts documentation:

trio/trio/_core/_run.py

Lines 1143 to 1146 in 4512ae3

* ``seconds_to_next_deadline`` (float): The time until the next
pending cancel scope deadline. May be negative if the deadline has
expired but we haven't yet processed cancellations. May be
:data:`~math.inf` if there are no pending deadlines.

I guess _autojumper should be corrected to do something like this:

statistics = _core.current_statistics() 
jump = statistics.seconds_to_next_deadline 
if 0 < jump < inf:
     self.jump(jump) 

What do you think ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions