aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2018-07-23 10:04:33 -0400
committerMarcoFalke <falke.marco@gmail.com>2018-07-23 10:04:35 -0400
commitab28b5b52702a81966416d68b04e5bde73b2c4d4 (patch)
treeeec10f66767708d08a339c2bbbff8b2a6e8d9267
parentc0a47da7250586dd2a6b7ba368a876ba8c6a15f2 (diff)
parent64b9f27e0e46142d01ed5070c544ca7a98183d56 (diff)
downloadbitcoin-ab28b5b52702a81966416d68b04e5bde73b2c4d4.tar.xz
Merge #13747: tests: Skip P2PConnection's is_closing() check when not available
64b9f27e0e Skip is_closing() check when not available. (Daniel Kraft) Pull request description: #13715 introduced a new check for `_transport.is_closing()` in mininode's `P2PConnection`'s. This function is [only available from Python 3.4.4](https://docs.python.org/3.4/library/asyncio-protocol.html#asyncio.BaseTransport.is_closing), though, while Bitcoin Core is supposed to support all Python 3.4 versions. In this change, we make the check conditional on `is_closing` being available. If it is not, then we revert to the behaviour before the check was introduced; this means that #13579 is not fixed for old systems, but at least the tests work as they used to do before. This includes a small refactoring from a one-line lambda to an inline function, because this makes the code easier to read with more and more conditions being added. Fixes #13745. Tree-SHA512: 15be03b8b49c40a946c5b354c5974858d14dc46283ad48ee25d9e269377077ce741c6b379b3f6581ab981cb65be799809afbb99da278caaa2d8d870fa4fb748f
-rwxr-xr-xtest/functional/test_framework/mininode.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/test/functional/test_framework/mininode.py b/test/functional/test_framework/mininode.py
index d5b1a90687..ccf767d357 100755
--- a/test/functional/test_framework/mininode.py
+++ b/test/functional/test_framework/mininode.py
@@ -179,7 +179,17 @@ class P2PConnection(asyncio.Protocol):
raise IOError('Not connected')
self._log_message("send", message)
tmsg = self._build_message(message)
- NetworkThread.network_event_loop.call_soon_threadsafe(lambda: self._transport and not self._transport.is_closing() and self._transport.write(tmsg))
+
+ def maybe_write():
+ if not self._transport:
+ return
+ # Python <3.4.4 does not have is_closing, so we have to check for
+ # its existence explicitly as long as Bitcoin Core supports all
+ # Python 3.4 versions.
+ if hasattr(self._transport, 'is_closing') and self._transport.is_closing():
+ return
+ self._transport.write(tmsg)
+ NetworkThread.network_event_loop.call_soon_threadsafe(maybe_write)
# Class utility methods