[Pkg-bitcoin-commits] [python-quamash] 203/269: Add strict test for scheduling of callbacks
Jonas Smedegaard
dr at jones.dk
Fri Nov 24 11:26:34 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository python-quamash.
commit 4529200a571e1405b395608f987e820e7c364820
Author: Jonas Wielicki <j.wielicki at sotecware.net>
Date: Thu Jan 15 19:20:21 2015 +0100
Add strict test for scheduling of callbacks
This test shows a difference to stock asyncio event loop. In stock
asyncio, writer_cb is called exactly once, due to fut_cb being called
before writer_cb gets a second chance. writer_cb gets thus removed and
is not called again.
This may be critical. The asyncio implementation shipping with Python
3.4.2 relies on this in the implementation of sock_connect (c.f.
selector_events.py:352--389 from that version), and not adhering to this
yields to odd results up to infinite loops of callbacks.
---
tests/test_qeventloop.py | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/tests/test_qeventloop.py b/tests/test_qeventloop.py
index ce68239..8425ab4 100644
--- a/tests/test_qeventloop.py
+++ b/tests/test_qeventloop.py
@@ -645,3 +645,25 @@ def test_remove_writer_idempotence(loop, sock_pair):
assert not removed0
assert removed1
assert not removed2
+
+
+def test_scheduling(loop, sock_pair):
+ s1, s2 = sock_pair
+ fd = s1.fileno()
+ cb_called = asyncio.Future()
+
+ def writer_cb(fut):
+ if fut.done():
+ cb_called.set_exception(
+ ValueError("writer_cb called twice")
+ )
+ fut.set_result(None)
+
+ def fut_cb(fut):
+ loop.remove_writer(fd)
+ cb_called.set_result(None)
+
+ fut = asyncio.Future()
+ fut.add_done_callback(fut_cb)
+ loop.add_writer(fd, writer_cb, fut)
+ loop.run_until_complete(cb_called)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/python-quamash.git
More information about the Pkg-bitcoin-commits
mailing list