From 7531c9891633bf777abc0230241d45399f0cbd7a Mon Sep 17 00:00:00 2001 From: Schuyler Duveen Date: Tue, 6 Jun 2017 13:11:33 -0400 Subject: [PATCH] =?UTF-8?q?fixes=20#3616:=20make=20sure=20there=20is=20alw?= =?UTF-8?q?ays=20one=20time=20that=20we=20test=20the=20sock=E2=80=A6=20(#4?= =?UTF-8?q?712)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- acme/acme/standalone_test.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/acme/acme/standalone_test.py b/acme/acme/standalone_test.py index 613258c97..c3beab34b 100644 --- a/acme/acme/standalone_test.py +++ b/acme/acme/standalone_test.py @@ -137,7 +137,6 @@ class TestSimpleTLSSNI01Server(unittest.TestCase): ) self.old_cwd = os.getcwd() os.chdir(self.test_cwd) - self.thread.start() def tearDown(self): os.chdir(self.old_cwd) @@ -146,13 +145,12 @@ class TestSimpleTLSSNI01Server(unittest.TestCase): def test_it(self): max_attempts = 5 - while max_attempts: - max_attempts -= 1 + for attempt in range(max_attempts): try: cert = crypto_util.probe_sni( b'localhost', b'0.0.0.0', self.port) except errors.Error: - self.assertTrue(max_attempts > 0, "Timeout!") + self.assertTrue(attempt + 1 < max_attempts, "Timeout!") time.sleep(1) # wait until thread starts else: self.assertEqual(jose.ComparableX509(cert), @@ -160,6 +158,11 @@ class TestSimpleTLSSNI01Server(unittest.TestCase): 'rsa2048_cert.pem')) break + if attempt == 0: + # the first attempt is always meant to fail, so we can test + # the socket failure code-path for probe_sni, as well + self.thread.start() + if __name__ == "__main__": unittest.main() # pragma: no cover