Skip to content

Commit e81f90f

Browse files
committed
Round delay in call_later()
* Fixes #233.
1 parent 7a4f00a commit e81f90f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

tests/test_base.py

+14
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ def cb(arg):
171171
self.loop.run_forever()
172172
self.assertEqual(calls, ['a'])
173173

174+
def test_call_later_rounding(self):
175+
# Refs #233, call_later() and call_at() shouldn't call cb early
176+
177+
def cb():
178+
self.loop.stop()
179+
180+
for i in range(8):
181+
self.loop.call_later(0.06 + 0.01, cb) # 0.06999999999999999
182+
started = time.monotonic()
183+
self.loop.run_forever()
184+
finished = time.monotonic()
185+
self.assertGreaterEqual(int(round((finished - started) * 1000)),
186+
70)
187+
174188
def test_call_at(self):
175189
if os.environ.get('TRAVIS_OS_NAME'):
176190
# Time seems to be really unpredictable on Travis.

uvloop/loop.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ cdef class Loop:
12541254
# infinity for a Python application.
12551255
delay = 3600 * 24 * 365 * 100
12561256

1257-
when = <uint64_t>(delay * 1000)
1257+
when = <uint64_t>round(delay * 1000)
12581258
if not args:
12591259
args = None
12601260
if when == 0:

0 commit comments

Comments
 (0)