mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-02 00:05:27 +00:00
addons/script: improve relability of reload test
The granularity of mtime is surprisingly bad. Make the tests more robust against this, and promote has_log back to a public method, now that we have a few legitimate examples.
This commit is contained in:
parent
44016a0de5
commit
0ba10b6109
@ -35,7 +35,7 @@ class RecordingMaster(mitmproxy.master.Master):
|
||||
for i in self.logs:
|
||||
print("%s: %s" % (i.level, i.msg), file=outf)
|
||||
|
||||
def _has_log(self, txt, level=None):
|
||||
def has_log(self, txt, level=None):
|
||||
for i in self.logs:
|
||||
if level and i.level != level:
|
||||
continue
|
||||
@ -45,7 +45,7 @@ class RecordingMaster(mitmproxy.master.Master):
|
||||
|
||||
async def await_log(self, txt, level=None):
|
||||
for i in range(20):
|
||||
if self._has_log(txt, level):
|
||||
if self.has_log(txt, level):
|
||||
return True
|
||||
else:
|
||||
await asyncio.sleep(0.1)
|
||||
|
@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
@ -123,8 +124,13 @@ class TestScript:
|
||||
assert await tctx.master.await_log("Loading")
|
||||
|
||||
tctx.master.clear()
|
||||
for i in range(20):
|
||||
f.write("\n")
|
||||
assert await tctx.master.await_log("Loading")
|
||||
if tctx.master.has_log("Loading"):
|
||||
break
|
||||
await asyncio.sleep(0.1)
|
||||
else:
|
||||
raise AssertionError("No reload seen")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_exception(self):
|
||||
|
@ -827,7 +827,7 @@ class TestServerConnect(tservers.HTTPProxyTest):
|
||||
self.set_addons(AFakeResponse())
|
||||
assert self.pathod("200").status_code == 200
|
||||
asyncio.sleep(0.1)
|
||||
assert not self.proxy.tmaster._has_log("serverconnect")
|
||||
assert not self.proxy.tmaster.has_log("serverconnect")
|
||||
|
||||
|
||||
class AKillRequest:
|
||||
|
@ -10,10 +10,10 @@ from mitmproxy import ctx
|
||||
@pytest.mark.asyncio
|
||||
async def test_recordingmaster():
|
||||
with taddons.context() as tctx:
|
||||
assert not tctx.master._has_log("nonexistent")
|
||||
assert not tctx.master.has_log("nonexistent")
|
||||
assert not tctx.master.has_event("nonexistent")
|
||||
ctx.log.error("foo")
|
||||
assert not tctx.master._has_log("foo", level="debug")
|
||||
assert not tctx.master.has_log("foo", level="debug")
|
||||
assert await tctx.master.await_log("foo", level="error")
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user