You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using an `int`, we need to do a double conversion, first to `float`
and then back to `int`, and due to rounding errors, this means there are
inconsistencies between the expected and actual values.
This is an example failure:
```
______________________ test_policy_skip_missed_and_drift _______________________
@hypothesis.given(
> tolerance=st.integers(min_value=0, max_value=_max_timedelta_microseconds),
**_calculate_next_tick_time_args,
)
tests/test_timer.py:148:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tolerance = 171726190479152817, now = 171726190479152817
scheduled_tick_time = -1, interval = 1
@hypothesis.given(
tolerance=st.integers(min_value=0, max_value=_max_timedelta_microseconds),
**_calculate_next_tick_time_args,
)
def test_policy_skip_missed_and_drift(
tolerance: int, now: int, scheduled_tick_time: int, interval: int
) -> None:
"""Test the SkipMissedAndDrift policy."""
hypothesis.assume(now >= scheduled_tick_time)
next_tick_time = SkipMissedAndDrift(
delay_tolerance=timedelta(microseconds=tolerance)
).calculate_next_tick_time(
now=now, interval=interval, scheduled_tick_time=scheduled_tick_time
)
if tolerance < interval:
assert next_tick_time > now
drift = now - scheduled_tick_time
if drift > tolerance:
> assert next_tick_time == now + interval
E assert 0 == (171726190479152817 + 1)
E Falsifying example: test_policy_skip_missed_and_drift(
E tolerance=171_726_190_479_152_817,
E now=171_726_190_479_152_817,
E scheduled_tick_time=-1,
E interval=1, # or any other generated value
E )
tests/test_timer.py:166: AssertionError
```
Using `float` directly ensures we are comparing the same values in the
tests and in the code.
Some explicit examples are now included in the hypothesis tests to
ensure this issue is not reintroduced.
Signed-off-by: Leandro Lucarella <[email protected]>
0 commit comments