diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-06-08 11:21:38 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-06-08 11:21:38 +1200 |
commit | b3bf754e539555351230cbb0887f8838c12fd23c (patch) | |
tree | 862b77357a28b85472bb48387e98e1d3519b625e /test | |
parent | a388ddfd781fd05a414c07cac8446ef151cbd1d2 (diff) | |
download | mitmproxy-b3bf754e539555351230cbb0887f8838c12fd23c.tar.gz mitmproxy-b3bf754e539555351230cbb0887f8838c12fd23c.tar.bz2 mitmproxy-b3bf754e539555351230cbb0887f8838c12fd23c.zip |
Simplify script concurrency helpers
We now have take() to prevent double-replies.
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/script/test_concurrent.py | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/test/mitmproxy/script/test_concurrent.py b/test/mitmproxy/script/test_concurrent.py index c2f169ad..62541f3f 100644 --- a/test/mitmproxy/script/test_concurrent.py +++ b/test/mitmproxy/script/test_concurrent.py @@ -1,29 +1,25 @@ -from threading import Event - from mitmproxy.script import Script from test.mitmproxy import tutils +from mitmproxy import controller +import time -class Dummy: - def __init__(self, reply): - self.reply = reply +class Thing: + def __init__(self): + self.reply = controller.DummyReply() @tutils.skip_appveyor def test_concurrent(): with Script(tutils.test_data.path("data/scripts/concurrent_decorator.py"), None) as s: - def reply(): - reply.acked.set() - reply.acked = Event() - - f1, f2 = Dummy(reply), Dummy(reply) + f1, f2 = Thing(), Thing() s.run("request", f1) - f1.reply() s.run("request", f2) - f2.reply() - assert f1.reply.acked == reply.acked - assert not reply.acked.is_set() - assert reply.acked.wait(10) + start = time.time() + while time.time() - start < 5: + if f1.reply.acked and f2.reply.acked: + return + raise ValueError("Script never acked") def test_concurrent_err(): |