mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
asyncio: cleanup and lint
Also fix a racy websocket test.
This commit is contained in:
parent
1f33c1c1a5
commit
14f461c5d5
@ -1,4 +1,3 @@
|
||||
import sys
|
||||
from mitmproxy import ctx
|
||||
from mitmproxy.utils import human
|
||||
|
||||
|
@ -85,7 +85,8 @@ class Master:
|
||||
mitmproxy_ctx.log = None
|
||||
mitmproxy_ctx.options = None
|
||||
|
||||
def tell(self, mtype, m):
|
||||
# This is a vestigial function that will go away in a refactor very soon
|
||||
def tell(self, mtype, m): # pragma: no cover
|
||||
m.reply = controller.DummyReply()
|
||||
self.event_queue.put((mtype, m))
|
||||
|
||||
@ -106,7 +107,7 @@ class Master:
|
||||
mtype, obj = await self.event_queue.get()
|
||||
except RuntimeError:
|
||||
return
|
||||
if mtype not in eventsequence.Events:
|
||||
if mtype not in eventsequence.Events: # pragma: no cover
|
||||
raise exceptions.ControlException("Unknown event %s" % repr(mtype))
|
||||
self.addons.handle_lifecycle(mtype, obj)
|
||||
self.event_queue.task_done()
|
||||
|
@ -3,7 +3,6 @@ import webbrowser
|
||||
import tornado.httpserver
|
||||
import tornado.ioloop
|
||||
from tornado.platform.asyncio import AsyncIOMainLoop
|
||||
import asyncio
|
||||
|
||||
from mitmproxy import addons
|
||||
from mitmproxy import log
|
||||
|
@ -331,7 +331,12 @@ class TestPong(_WebSocketTest):
|
||||
|
||||
assert frame.header.opcode == websockets.OPCODE.PONG
|
||||
assert frame.payload == b'foobar'
|
||||
assert self.master.has_log("Pong Received from server", "info")
|
||||
for i in range(20):
|
||||
if self.master.has_log("Pong Received from server", "info"):
|
||||
break
|
||||
time.sleep(0.01)
|
||||
else:
|
||||
raise AssertionError("No pong seen")
|
||||
|
||||
|
||||
class TestClose(_WebSocketTest):
|
||||
|
@ -7,7 +7,7 @@ import mitmproxy.io
|
||||
from mitmproxy import flowfilter
|
||||
from mitmproxy import options
|
||||
from mitmproxy.io import tnetstring
|
||||
from mitmproxy.exceptions import FlowReadException, ReplayException, ControlException
|
||||
from mitmproxy.exceptions import FlowReadException, ReplayException
|
||||
from mitmproxy import flow
|
||||
from mitmproxy import http
|
||||
from mitmproxy.net import http as net_http
|
||||
|
Loading…
Reference in New Issue
Block a user