From 00f88adbb20685bba7171a51e6271c43087add52 Mon Sep 17 00:00:00 2001 From: PiRK Date: Tue, 10 Oct 2023 12:19:18 +0200 Subject: [PATCH] [electrum] better handle timeouts in test_interface Summary: Tests are failing on CI because we don't catch the correct error for python < 3.10 badssl.com seems to be unresponsive, lately. If this keeps happening, this test should be removed to not slow down the test suite unnecessarily. Test Plan: `python -m electrumabc.tests.test_interface` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D14619 --- electrumabc/tests/test_interface.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/electrumabc/tests/test_interface.py b/electrumabc/tests/test_interface.py index c958ff38cd72..d87862343a22 100644 --- a/electrumabc/tests/test_interface.py +++ b/electrumabc/tests/test_interface.py @@ -1,3 +1,4 @@ +import socket import ssl import unittest @@ -18,8 +19,14 @@ def has_ca_signed_valid_cert(self, server: str) -> bool: else: self.skipTest("This test requires an internet connection.") return bool(s) - except TimeoutError: + except (TimeoutError, socket.timeout): + # In Python >= 3.10, socket.timeout is an alias for TimeoutError. + # For lower versions of python we need to catch both. + # socket.timeout is deprecated, so when support for Python 3.9 is + # dropped it should be removed. retries += 1 + # if we are here, it means the request keeps timing out + self.skipTest(f"Skipping test after 5 timeouts. {server} must be down.") def test_verify_good_ca_cert(self): # These are also a wildcard certificate