Skip to content

Commit 8f037a6

Browse files
fantix1st1
authored andcommitted
Round delay in call_later()
* Fixes #233.
1 parent d9a111b commit 8f037a6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Diff for: tests/test_base.py

+13
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ def cb(arg):
205205
self.loop.run_forever()
206206
self.assertEqual(calls, ['a'])
207207

208+
def test_call_later_rounding(self):
209+
# Refs #233, call_later() and call_at() shouldn't call cb early
210+
211+
def cb():
212+
self.loop.stop()
213+
214+
for i in range(8):
215+
self.loop.call_later(0.06 + 0.01, cb) # 0.06999999999999999
216+
started = int(round(self.loop.time() * 1000))
217+
self.loop.run_forever()
218+
finished = int(round(self.loop.time() * 1000))
219+
self.assertGreaterEqual(finished - started, 70)
220+
208221
def test_call_at(self):
209222
if os.environ.get('TRAVIS_OS_NAME'):
210223
# Time seems to be really unpredictable on Travis.

Diff for: uvloop/loop.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ cdef class Loop:
12911291
# infinity for a Python application.
12921292
delay = 3600 * 24 * 365 * 100
12931293

1294-
when = <uint64_t>(delay * 1000)
1294+
when = <uint64_t>round(delay * 1000)
12951295
if not args:
12961296
args = None
12971297
if when == 0:

0 commit comments

Comments
 (0)