1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
From: Stefano Rivera <stefanor@debian.org>
Date: Wed, 18 May 2022 09:21:27 -0400
Subject: Handle ConnectionRefusedError when connecting to 223.255.255.254
If the tests are run from an environment with a firewall, they may be
refused instead of timing out.
Just skip the test.
Forwarded: https://github.com/ronf/asyncssh/pull/480
---
tests/test_connection.py | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/tests/test_connection.py b/tests/test_connection.py
index 9a3871c..9eec850 100644
--- a/tests/test_connection.py
+++ b/tests/test_connection.py
@@ -425,23 +425,32 @@ class _TestConnection(ServerTestCase):
async def test_connect_timeout_exceeded(self):
"""Test connect timeout exceeded"""
- with self.assertRaises(asyncio.TimeoutError):
- await asyncssh.connect('223.255.255.254', connect_timeout=1)
+ try:
+ with self.assertRaises(asyncio.TimeoutError):
+ await asyncssh.connect('223.255.255.254', connect_timeout=1)
+ except ConnectionRefusedError:
+ raise unittest.SkipTest("Outboand connection firewalled")
@asynctest
async def test_connect_timeout_exceeded_string(self):
"""Test connect timeout exceeded with string value"""
- with self.assertRaises(asyncio.TimeoutError):
- await asyncssh.connect('223.255.255.254', connect_timeout='0m1s')
+ try:
+ with self.assertRaises(asyncio.TimeoutError):
+ await asyncssh.connect('223.255.255.254', connect_timeout='0m1s')
+ except ConnectionRefusedError:
+ raise unittest.SkipTest("Outboand connection firewalled")
@asynctest
async def test_connect_timeout_exceeded_tunnel(self):
"""Test connect timeout exceeded"""
- with self.assertRaises(asyncio.TimeoutError):
- await asyncssh.listen(server_host_keys=['skey'],
- tunnel='223.255.255.254', connect_timeout=1)
+ try:
+ with self.assertRaises(asyncio.TimeoutError):
+ await asyncssh.listen(server_host_keys=['skey'],
+ tunnel='223.255.255.254', connect_timeout=1)
+ except ConnectionRefusedError:
+ raise unittest.SkipTest("Outboand connection firewalled")
@asynctest
async def test_invalid_connect_timeout(self):
|