aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2018-04-23 13:19:20 +1200
committerAldo Cortesi <aldo@nullcube.com>2018-04-23 13:19:20 +1200
commit0ba10b61090274a1f2ca70a8fb1d68830cb44607 (patch)
tree0dae6d1c8626e2399a31564ff3275149f87580e0
parent44016a0de519469792769f7b78c37e7de9bfde24 (diff)
downloadmitmproxy-0ba10b61090274a1f2ca70a8fb1d68830cb44607.tar.gz
mitmproxy-0ba10b61090274a1f2ca70a8fb1d68830cb44607.tar.bz2
mitmproxy-0ba10b61090274a1f2ca70a8fb1d68830cb44607.zip
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.
-rw-r--r--mitmproxy/test/taddons.py4
-rw-r--r--test/mitmproxy/addons/test_script.py10
-rw-r--r--test/mitmproxy/proxy/test_server.py2
-rw-r--r--test/mitmproxy/test_taddons.py4
4 files changed, 13 insertions, 7 deletions
diff --git a/mitmproxy/test/taddons.py b/mitmproxy/test/taddons.py
index e0e4fef9..0505f9f7 100644
--- a/mitmproxy/test/taddons.py
+++ b/mitmproxy/test/taddons.py
@@ -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)
diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py
index fad514ae..ea942d34 100644
--- a/test/mitmproxy/addons/test_script.py
+++ b/test/mitmproxy/addons/test_script.py
@@ -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()
- f.write("\n")
- assert await tctx.master.await_log("Loading")
+ for i in range(20):
+ f.write("\n")
+ 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):
diff --git a/test/mitmproxy/proxy/test_server.py b/test/mitmproxy/proxy/test_server.py
index d7836104..3cb35138 100644
--- a/test/mitmproxy/proxy/test_server.py
+++ b/test/mitmproxy/proxy/test_server.py
@@ -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:
diff --git a/test/mitmproxy/test_taddons.py b/test/mitmproxy/test_taddons.py
index 39dd65c2..67f64463 100644
--- a/test/mitmproxy/test_taddons.py
+++ b/test/mitmproxy/test_taddons.py
@@ -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")