From 7e73e5fa51fb59ee1937bd8f634834bb420ff903 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 3 Apr 2018 09:46:11 +1200 Subject: [PATCH] asyncio: factor out test server startup wait --- test/mitmproxy/proxy/protocol/test_http2.py | 4 ---- test/mitmproxy/proxy/protocol/test_websocket.py | 4 ---- test/mitmproxy/tservers.py | 11 +++++++---- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/test/mitmproxy/proxy/protocol/test_http2.py b/test/mitmproxy/proxy/protocol/test_http2.py index 1cc364020..58114904f 100644 --- a/test/mitmproxy/proxy/protocol/test_http2.py +++ b/test/mitmproxy/proxy/protocol/test_http2.py @@ -92,10 +92,6 @@ class _Http2TestBase: cls.options = cls.get_options() cls.proxy = tservers.ProxyThread(tservers.TestMaster, cls.options) cls.proxy.start() - while True: - if cls.proxy.tmaster: - break - time.sleep(0.01) @classmethod def teardown_class(cls): diff --git a/test/mitmproxy/proxy/protocol/test_websocket.py b/test/mitmproxy/proxy/protocol/test_websocket.py index f64f500c8..e5ed8e9d1 100644 --- a/test/mitmproxy/proxy/protocol/test_websocket.py +++ b/test/mitmproxy/proxy/protocol/test_websocket.py @@ -54,10 +54,6 @@ class _WebSocketTestBase: cls.options = cls.get_options() cls.proxy = tservers.ProxyThread(tservers.TestMaster, cls.options) cls.proxy.start() - while True: - if cls.proxy.tmaster: - break - time.sleep(0.01) @classmethod def teardown_class(cls): diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py index d72ca1382..7feb90b76 100644 --- a/test/mitmproxy/tservers.py +++ b/test/mitmproxy/tservers.py @@ -121,6 +121,13 @@ class ProxyThread(threading.Thread): self.tmaster.reset(addons) self.tmaster.addons.trigger("tick") + def start(self): + super().start() + while True: + if self.tmaster: + break + time.sleep(0.01) + class ProxyTestBase: # Test Configuration @@ -142,10 +149,6 @@ class ProxyTestBase: cls.options = cls.get_options() cls.proxy = ProxyThread(cls.masterclass, cls.options) cls.proxy.start() - while True: - if cls.proxy.tmaster: - break - time.sleep(0.01) @classmethod def teardown_class(cls):