From 4090085b17f6a652cc0ba1a6d9c7df71f81745ed Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Sun, 18 Oct 2015 12:22:54 +0000 Subject: [PATCH] Avoid race conditions in acme.standalone_test. --- acme/acme/standalone_test.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/acme/acme/standalone_test.py b/acme/acme/standalone_test.py index 14d212d6e..2230bfccf 100644 --- a/acme/acme/standalone_test.py +++ b/acme/acme/standalone_test.py @@ -35,14 +35,19 @@ class ACMEServerMixinTest(unittest.TestCase): def setUp(self): from acme.standalone import ACMEServerMixin + class _MockHandler(socketserver.BaseRequestHandler): + def handle(self): + self.request.sendall(b"DONE") + class _MockServer(socketserver.TCPServer, ACMEServerMixin): def __init__(self, *args, **kwargs): socketserver.TCPServer.__init__(self, *args, **kwargs) ACMEServerMixin.__init__(self) - self.server = _MockServer(("", 0), socketserver.BaseRequestHandler) + + self.server = _MockServer(("", 0), _MockHandler) def _busy_wait(self): # pragma: no cover - # This function is used to avoid race coditions in tests, but + # This function is used to avoid race conditions in tests, but # not all of the functionality is always used, hence "no # cover" while True: @@ -53,6 +58,7 @@ class ACMEServerMixinTest(unittest.TestCase): except socket.error: pass else: + sock.recv(4) # wait until handle_request is actually called break finally: sock.close()