asyncio: cleanup and lint

Also fix a racy websocket test.
This commit is contained in:
Aldo Cortesi 2018-04-02 15:47:23 +12:00
parent 1f33c1c1a5
commit 14f461c5d5
5 changed files with 10 additions and 6 deletions

View File

@ -1,4 +1,3 @@
import sys
from mitmproxy import ctx
from mitmproxy.utils import human

View File

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

View File

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

View File

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

View File

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