aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-10-19 01:26:08 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-10-19 01:26:08 +0200
commit37cc6ae0bbb32e528435f821469d36055574a810 (patch)
treeddbdc667090fc72a9c2e9da7dd46cd05d7439127 /test
parente1148584380058f264b7aa7e9493115e4e8f2bbe (diff)
downloadmitmproxy-37cc6ae0bbb32e528435f821469d36055574a810.tar.gz
mitmproxy-37cc6ae0bbb32e528435f821469d36055574a810.tar.bz2
mitmproxy-37cc6ae0bbb32e528435f821469d36055574a810.zip
fix race conditions in tests
Diffstat (limited to 'test')
-rw-r--r--test/test_flow.py3
-rw-r--r--test/test_server.py12
2 files changed, 15 insertions, 0 deletions
diff --git a/test/test_flow.py b/test/test_flow.py
index f0844536..92c5b19d 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -600,6 +600,9 @@ class TestFlowMaster:
f.intercepting = True
assert "intercepting" in fm.replay_request(f)
+ f.live = True
+ assert "live" in fm.replay_request(f)
+
def test_script_reqerr(self):
s = flow.State()
fm = flow.FlowMaster(None, s)
diff --git a/test/test_server.py b/test/test_server.py
index 6035b3a4..c81eab2b 100644
--- a/test/test_server.py
+++ b/test/test_server.py
@@ -19,6 +19,17 @@ class CommonMixin:
def test_large(self):
assert len(self.pathod("200:b@50k").content) == 1024*50
+ @staticmethod
+ def wait_until_not_live(flow):
+ """
+ Race condition: We don't want to replay the flow while it is still live.
+ """
+ s = time.time()
+ while flow.live:
+ time.sleep(0.001)
+ if time.time() - s > 5:
+ raise RuntimeError("Flow is live for too long.")
+
def test_replay(self):
assert self.pathod("304").status_code == 304
if isinstance(self, tservers.HTTPUpstreamProxTest) and self.ssl:
@@ -28,6 +39,7 @@ class CommonMixin:
l = self.master.state.view[-1]
assert l.response.code == 304
l.request.path = "/p/305"
+ self.wait_until_not_live(l)
rt = self.master.replay_request(l, block=True)
assert l.response.code == 305