mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
asyncio: make http2 tests pass
This commit is contained in:
parent
28a8ddc0e8
commit
2b040ff093
@ -92,13 +92,12 @@ class Master:
|
|||||||
|
|
||||||
async def main(self):
|
async def main(self):
|
||||||
while True:
|
while True:
|
||||||
if self.should_exit.is_set():
|
try:
|
||||||
|
mtype, obj = await self.event_queue.get()
|
||||||
|
except RuntimeError:
|
||||||
return
|
return
|
||||||
mtype, obj = await self.event_queue.get()
|
|
||||||
if mtype not in eventsequence.Events:
|
if mtype not in eventsequence.Events:
|
||||||
raise exceptions.ControlException(
|
raise exceptions.ControlException("Unknown event %s" % repr(mtype))
|
||||||
"Unknown event %s" % repr(mtype)
|
|
||||||
)
|
|
||||||
self.addons.handle_lifecycle(mtype, obj)
|
self.addons.handle_lifecycle(mtype, obj)
|
||||||
self.event_queue.task_done()
|
self.event_queue.task_done()
|
||||||
|
|
||||||
@ -117,8 +116,12 @@ class Master:
|
|||||||
self.start()
|
self.start()
|
||||||
asyncio.ensure_future(self.main())
|
asyncio.ensure_future(self.main())
|
||||||
asyncio.ensure_future(self.tick())
|
asyncio.ensure_future(self.tick())
|
||||||
asyncio.get_event_loop().run_forever()
|
loop = asyncio.get_event_loop()
|
||||||
self.shutdown()
|
try:
|
||||||
|
loop.run_forever()
|
||||||
|
finally:
|
||||||
|
self.shutdown()
|
||||||
|
loop.close()
|
||||||
self.addons.trigger("done")
|
self.addons.trigger("done")
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
@ -6,11 +6,11 @@ import tempfile
|
|||||||
import traceback
|
import traceback
|
||||||
import pytest
|
import pytest
|
||||||
import h2
|
import h2
|
||||||
|
import time
|
||||||
|
|
||||||
from mitmproxy import options
|
from mitmproxy import options
|
||||||
|
|
||||||
import mitmproxy.net
|
import mitmproxy.net
|
||||||
from mitmproxy.addons import core
|
|
||||||
from ...net import tservers as net_tservers
|
from ...net import tservers as net_tservers
|
||||||
from mitmproxy import exceptions
|
from mitmproxy import exceptions
|
||||||
from mitmproxy.net.http import http1, http2
|
from mitmproxy.net.http import http1, http2
|
||||||
@ -92,6 +92,10 @@ class _Http2TestBase:
|
|||||||
cls.options = cls.get_options()
|
cls.options = cls.get_options()
|
||||||
cls.proxy = tservers.ProxyThread(tservers.TestMaster, cls.options)
|
cls.proxy = tservers.ProxyThread(tservers.TestMaster, cls.options)
|
||||||
cls.proxy.start()
|
cls.proxy.start()
|
||||||
|
while True:
|
||||||
|
if cls.proxy.tmaster:
|
||||||
|
break
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def teardown_class(cls):
|
def teardown_class(cls):
|
||||||
@ -118,6 +122,7 @@ class _Http2TestBase:
|
|||||||
def teardown(self):
|
def teardown(self):
|
||||||
if self.client:
|
if self.client:
|
||||||
self.client.close()
|
self.client.close()
|
||||||
|
self.server.server.wait_for_silence()
|
||||||
|
|
||||||
def setup_connection(self):
|
def setup_connection(self):
|
||||||
self.client = mitmproxy.net.tcp.TCPClient(("127.0.0.1", self.proxy.port))
|
self.client = mitmproxy.net.tcp.TCPClient(("127.0.0.1", self.proxy.port))
|
||||||
|
@ -122,7 +122,6 @@ class ProxyThread(threading.Thread):
|
|||||||
self.tmaster.addons.trigger("tick")
|
self.tmaster.addons.trigger("tick")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ProxyTestBase:
|
class ProxyTestBase:
|
||||||
# Test Configuration
|
# Test Configuration
|
||||||
ssl = None
|
ssl = None
|
||||||
|
Loading…
Reference in New Issue
Block a user