Commit 62e3b300 authored by Jason Madden's avatar Jason Madden

Fix test__systemerror (#1058) again

It depended on when the timer expired relative to when we intered the
loop for the first time. It could still run before our other callbacks
did if it had expired before we entered the loop.

I suppose that going to the static 'extern' functions changed the
timing of things enough that this exposed itself.
parent 7e504fde
......@@ -150,9 +150,19 @@
a file descriptor it is using in a watcher may cause the entire
process to be exited.
- There may be occasional otherwise unexplained and hard to
duplicate crashes. If you can duplicate a crash, **please** submit
an issue.
Feedback and pull requests are welcome, especially to address the
issues mentioned above.
Other differences include:
- The order in which timers and other callbacks are invoked may be
different than in libev. In particular, timers and IO callbacks
happen in a different order.
Again, this is extremely experimental and all of it is subject to
change.
......
......@@ -193,7 +193,6 @@ lint-py27: $(PY27)
test-py27: $(PY27)
PYTHON=python2.7.14 PATH=$(BUILD_RUNTIMES)/versions/python2.7.14/bin:$(PATH) make develop allbackendtest
PYTHON=python2.7.14 PATH=$(BUILD_RUNTIMES)/versions/python2.7.14/bin:$(PATH) TRAVIS= cd src/greentest/2.7 && PYTHONFAULTHANDLER=1 && PYTHONPATH=.. GEVENT_CORE_CFFI_ONLY=libuv ${PYTHON} -m monkey_test test_subprocess.py
test-py278: $(PY278)
ls $(BUILD_RUNTIMES)/versions/python2.7.8/bin/
......
......@@ -180,6 +180,7 @@ class loop(AbstractLoop):
# From the loop inside uv_run:
# while True:
# uv__update_time(loop);
# uv__run_timers(loop);
# ran_pending = uv__run_pending(loop);
# uv__run_idle(loop);
......@@ -188,13 +189,14 @@ class loop(AbstractLoop):
# uv__io_poll(loop, timeout);
# uv__run_check(loop);
# libuv looks something like this (pseudo code because the real code is
# libev looks something like this (pseudo code because the real code is
# hard to read):
#
# do {
# run_prepare_callbacks();
# timeout = min(time of all timers or normal block time)
# io_poll()
# update_now(); calculate_expired_timers();
# run_timers()
# run_pending()
# }
......@@ -210,6 +212,13 @@ class loop(AbstractLoop):
# If we use a 0 duration timer, we can get stuck in a timer loop.
# Python 3.6 fails in test_ftplib.py
# As a final note, if we have not yet entered the loop *at
# all*, and a timer was created with a duration shorter than
# the amount of time it took for us to enter the loop in the
# first place, it may expire and get called before our callback
# does. This could also lead to test__systemerror:TestCallback
# appearing to be flaky.
libuv.uv_check_start(self._timer0, libuv.python_prepare_callback)
......@@ -331,6 +340,7 @@ class loop(AbstractLoop):
def run(self, nowait=False, once=False):
_dbg("Entering libuv.uv_run")
# we can only respect one flag or the other.
# nowait takes precedence because it can't block
mode = libuv.UV_RUN_DEFAULT
......
......@@ -72,12 +72,24 @@ class TestCallback(Test):
# libuv: See the notes in libuv/loop.py:loop._start_callback_timer
# If that's broken, test_exception can fail sporadically.
# If the issue is the same, then adding `gevent.sleep(0)` here
# will solve it.
# will solve it. There's also a race condition for the first loop,
# so we sleep twice.
assert not self.x.pending, self.x
def start(self, *args):
self.x = get_hub().loop.run_callback(*args)
if greentest.LIBUV:
def test_exception(self):
# This call will enter the loop for the very first time (if we're running
# standalone). On libuv, where timers run first, that means that depending on the
# amount of time that elapses between the call to uv_timer_start and uv_run,
# this timer might fire before our check or prepare watchers, and hence callbacks,
# run.
# We make this call now so that the call in the super class is guaranteed to be
# somewhere in the loop and not subject to that race condition.
gevent.sleep(0.001)
super(TestCallback, self).test_exception()
class TestSpawn(Test):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment