mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
additional test speedups
This commit is contained in:
parent
2f725e5f02
commit
8ce4bc7142
@ -39,11 +39,14 @@ class RecordingMaster(mitmproxy.master.Master):
|
||||
return False
|
||||
|
||||
async def await_log(self, txt, level=None):
|
||||
# start with a sleep(0), which lets all other coroutines advance.
|
||||
# often this is enough to not sleept at all.
|
||||
await asyncio.sleep(0)
|
||||
for i in range(20):
|
||||
if self.has_log(txt, level):
|
||||
return True
|
||||
else:
|
||||
await asyncio.sleep(0.1)
|
||||
await asyncio.sleep(0.001)
|
||||
return False
|
||||
|
||||
def clear(self):
|
||||
|
@ -246,6 +246,7 @@ class TestScriptLoader:
|
||||
os.remove(tdata.path("mitmproxy/data/addonscripts/dummy.py"))
|
||||
|
||||
await tctx.master.await_log("Removing")
|
||||
await asyncio.sleep(0.1)
|
||||
assert not tctx.options.scripts
|
||||
assert not sl.addons
|
||||
|
||||
@ -302,7 +303,7 @@ class TestScriptLoader:
|
||||
]
|
||||
)
|
||||
|
||||
await tctx.master.await_log("c configure")
|
||||
await tctx.master.await_log("b configure")
|
||||
debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
|
||||
assert debug == [
|
||||
'c configure',
|
||||
@ -318,7 +319,7 @@ class TestScriptLoader:
|
||||
"%s/a.py" % rec,
|
||||
]
|
||||
)
|
||||
await tctx.master.await_log("Loading")
|
||||
await tctx.master.await_log("e configure")
|
||||
debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
|
||||
assert debug == [
|
||||
'c done',
|
||||
|
@ -1,37 +0,0 @@
|
||||
import mitmproxy
|
||||
record = []
|
||||
|
||||
|
||||
def clientconnect(cc):
|
||||
mitmproxy.ctx.log("XCLIENTCONNECT")
|
||||
record.append("clientconnect")
|
||||
|
||||
|
||||
def serverconnect(cc):
|
||||
mitmproxy.ctx.log("XSERVERCONNECT")
|
||||
record.append("serverconnect")
|
||||
|
||||
|
||||
def request(f):
|
||||
mitmproxy.ctx.log("XREQUEST")
|
||||
record.append("request")
|
||||
|
||||
|
||||
def response(f):
|
||||
mitmproxy.ctx.log("XRESPONSE")
|
||||
record.append("response")
|
||||
|
||||
|
||||
def responseheaders(f):
|
||||
mitmproxy.ctx.log("XRESPONSEHEADERS")
|
||||
record.append("responseheaders")
|
||||
|
||||
|
||||
def clientdisconnect(cc):
|
||||
mitmproxy.ctx.log("XCLIENTDISCONNECT")
|
||||
record.append("clientdisconnect")
|
||||
|
||||
|
||||
def error(cc):
|
||||
mitmproxy.ctx.log("XERROR")
|
||||
record.append("error")
|
@ -75,13 +75,13 @@ class Test_Format(unittest.TestCase):
|
||||
self.assertEqual((expect, b''), tnetstring.pop(data))
|
||||
|
||||
def test_roundtrip_format_random(self):
|
||||
for _ in range(500):
|
||||
for _ in range(10):
|
||||
v = get_random_object()
|
||||
self.assertEqual(v, tnetstring.loads(tnetstring.dumps(v)))
|
||||
self.assertEqual((v, b""), tnetstring.pop(tnetstring.dumps(v)))
|
||||
|
||||
def test_roundtrip_format_unicode(self):
|
||||
for _ in range(500):
|
||||
for _ in range(10):
|
||||
v = get_random_object()
|
||||
self.assertEqual(v, tnetstring.loads(tnetstring.dumps(v)))
|
||||
self.assertEqual((v, b''), tnetstring.pop(tnetstring.dumps(v)))
|
||||
@ -111,7 +111,7 @@ class Test_FileLoading(unittest.TestCase):
|
||||
self.assertEqual(b'OK', s.read())
|
||||
|
||||
def test_roundtrip_file_random(self):
|
||||
for _ in range(500):
|
||||
for _ in range(10):
|
||||
v = get_random_object()
|
||||
s = io.BytesIO()
|
||||
tnetstring.dump(v, s)
|
||||
|
Loading…
Reference in New Issue
Block a user