From 5fc4fc28b682dda8ad2d3fd5b5ddf91938da5258 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 21 Feb 2017 16:56:48 +0800 Subject: [PATCH] Add test for @concurrent decorator in class. --- .../addonscripts/concurrent_decorator_class.py | 13 +++++++++++++ test/mitmproxy/script/test_concurrent.py | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/mitmproxy/data/addonscripts/concurrent_decorator_class.py diff --git a/test/mitmproxy/data/addonscripts/concurrent_decorator_class.py b/test/mitmproxy/data/addonscripts/concurrent_decorator_class.py new file mode 100644 index 000000000..bd047c99a --- /dev/null +++ b/test/mitmproxy/data/addonscripts/concurrent_decorator_class.py @@ -0,0 +1,13 @@ +import time +from mitmproxy.script import concurrent + + +class ConcurrentClass: + + @concurrent + def request(flow): + time.sleep(0.1) + + +def start(): + return ConcurrentClass() diff --git a/test/mitmproxy/script/test_concurrent.py b/test/mitmproxy/script/test_concurrent.py index fb932d9a2..e81c023dd 100644 --- a/test/mitmproxy/script/test_concurrent.py +++ b/test/mitmproxy/script/test_concurrent.py @@ -44,3 +44,21 @@ class TestConcurrent(tservers.MasterTest): ) sc.start() assert "decorator not supported" in tctx.master.event_log[0][1] + + def test_concurrent_class(self): + with taddons.context() as tctx: + sc = script.Script( + tutils.test_data.path( + "mitmproxy/data/addonscripts/concurrent_decorator_class.py" + ) + ) + sc.start() + + f1, f2 = tflow.tflow(), tflow.tflow() + tctx.cycle(sc, f1) + tctx.cycle(sc, f2) + start = time.time() + while time.time() - start < 5: + if f1.reply.state == f2.reply.state == "committed": + return + raise ValueError("Script never acked")