aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/master.py17
-rw-r--r--test/mitmproxy/proxy/protocol/test_http2.py7
-rw-r--r--test/mitmproxy/tservers.py1
3 files changed, 16 insertions, 9 deletions
diff --git a/mitmproxy/master.py b/mitmproxy/master.py
index 2f47ae09..b1dd7d52 100644
--- a/mitmproxy/master.py
+++ b/mitmproxy/master.py
@@ -92,13 +92,12 @@ class Master:
async def main(self):
while True:
- if self.should_exit.is_set():
+ try:
+ mtype, obj = await self.event_queue.get()
+ except RuntimeError:
return
- mtype, obj = await self.event_queue.get()
if mtype not in eventsequence.Events:
- raise exceptions.ControlException(
- "Unknown event %s" % repr(mtype)
- )
+ raise exceptions.ControlException("Unknown event %s" % repr(mtype))
self.addons.handle_lifecycle(mtype, obj)
self.event_queue.task_done()
@@ -117,8 +116,12 @@ class Master:
self.start()
asyncio.ensure_future(self.main())
asyncio.ensure_future(self.tick())
- asyncio.get_event_loop().run_forever()
- self.shutdown()
+ loop = asyncio.get_event_loop()
+ try:
+ loop.run_forever()
+ finally:
+ self.shutdown()
+ loop.close()
self.addons.trigger("done")
def shutdown(self):
diff --git a/test/mitmproxy/proxy/protocol/test_http2.py b/test/mitmproxy/proxy/protocol/test_http2.py
index 8b929995..1cc36402 100644
--- a/test/mitmproxy/proxy/protocol/test_http2.py
+++ b/test/mitmproxy/proxy/protocol/test_http2.py
@@ -6,11 +6,11 @@ import tempfile
import traceback
import pytest
import h2
+import time
from mitmproxy import options
import mitmproxy.net
-from mitmproxy.addons import core
from ...net import tservers as net_tservers
from mitmproxy import exceptions
from mitmproxy.net.http import http1, http2
@@ -92,6 +92,10 @@ 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):
@@ -118,6 +122,7 @@ class _Http2TestBase:
def teardown(self):
if self.client:
self.client.close()
+ self.server.server.wait_for_silence()
def setup_connection(self):
self.client = mitmproxy.net.tcp.TCPClient(("127.0.0.1", self.proxy.port))
diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py
index 18e4f27d..d72ca138 100644
--- a/test/mitmproxy/tservers.py
+++ b/test/mitmproxy/tservers.py
@@ -122,7 +122,6 @@ class ProxyThread(threading.Thread):
self.tmaster.addons.trigger("tick")
-
class ProxyTestBase:
# Test Configuration
ssl = None