From 37cc6ae0bbb32e528435f821469d36055574a810 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 19 Oct 2014 01:26:08 +0200 Subject: fix race conditions in tests --- test/test_flow.py | 3 +++ test/test_server.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) (limited to 'test') 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 -- cgit v1.2.3