Skip to content

Commit

Permalink
Round delay in call_later()
Browse files Browse the repository at this point in the history
* Fixes #233.
  • Loading branch information
fantix authored and 1st1 committed Mar 20, 2019
1 parent d9a111b commit 8f037a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions tests/test_base.py
Expand Up @@ -205,6 +205,19 @@ def cb(arg):
self.loop.run_forever()
self.assertEqual(calls, ['a'])

def test_call_later_rounding(self):
# Refs #233, call_later() and call_at() shouldn't call cb early

def cb():
self.loop.stop()

for i in range(8):
self.loop.call_later(0.06 + 0.01, cb) # 0.06999999999999999
started = int(round(self.loop.time() * 1000))
self.loop.run_forever()
finished = int(round(self.loop.time() * 1000))
self.assertGreaterEqual(finished - started, 70)

def test_call_at(self):
if os.environ.get('TRAVIS_OS_NAME'):
# Time seems to be really unpredictable on Travis.
Expand Down
2 changes: 1 addition & 1 deletion uvloop/loop.pyx
Expand Up @@ -1291,7 +1291,7 @@ cdef class Loop:
# infinity for a Python application.
delay = 3600 * 24 * 365 * 100

when = <uint64_t>(delay * 1000)
when = <uint64_t>round(delay * 1000)
if not args:
args = None
if when == 0:
Expand Down

0 comments on commit 8f037a6

Please sign in to comment.