asyncio: make http2 tests pass

This commit is contained in:
Aldo Cortesi 2018-04-02 11:03:05 +12:00
parent 28a8ddc0e8
commit 2b040ff093
3 changed files with 16 additions and 9 deletions

View File

@ -92,13 +92,12 @@ class Master:
async def main(self):
while True:
if self.should_exit.is_set():
return
try:
mtype, obj = await self.event_queue.get()
except RuntimeError:
return
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()
loop = asyncio.get_event_loop()
try:
loop.run_forever()
finally:
self.shutdown()
loop.close()
self.addons.trigger("done")
def shutdown(self):

View File

@ -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))

View File

@ -122,7 +122,6 @@ class ProxyThread(threading.Thread):
self.tmaster.addons.trigger("tick")
class ProxyTestBase:
# Test Configuration
ssl = None