From 4f5930ec5dc4dba485d7a8c6ad4ed6ca18eb85fc Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 4 Feb 2022 17:07:13 +0100 Subject: [PATCH] simplify concurrency tests --- test/mitmproxy/script/test_concurrent.py | 30 ++++-------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/test/mitmproxy/script/test_concurrent.py b/test/mitmproxy/script/test_concurrent.py index dd2d8a0aa..71c74bf67 100644 --- a/test/mitmproxy/script/test_concurrent.py +++ b/test/mitmproxy/script/test_concurrent.py @@ -7,18 +7,14 @@ from mitmproxy.test import tflow from mitmproxy.test import taddons -class Thing: - def __init__(self): - self.live = True - - class TestConcurrent: @pytest.mark.asyncio - async def test_concurrent(self, tdata): + @pytest.mark.parametrize("addon", ["concurrent_decorator.py", "concurrent_decorator_class.py"]) + async def test_concurrent(self, addon, tdata): with taddons.context() as tctx: sc = tctx.script( tdata.path( - "mitmproxy/data/addonscripts/concurrent_decorator.py" + f"mitmproxy/data/addonscripts/{addon}" ) ) f1, f2 = tflow.tflow(), tflow.tflow() @@ -28,7 +24,8 @@ class TestConcurrent: tctx.cycle(sc, f2), ) end = time.time() - assert 0.3 < end - start < 0.7 + # This test may fail on overloaded CI systems, increase upper bound if necessary. + assert 0.3 < end - start < 1 @pytest.mark.asyncio async def test_concurrent_err(self, tdata): @@ -39,20 +36,3 @@ class TestConcurrent: ) ) await tctx.master.await_log("decorator not supported") - - @pytest.mark.asyncio - async def test_concurrent_class(self, tdata): - with taddons.context() as tctx: - sc = tctx.script( - tdata.path( - "mitmproxy/data/addonscripts/concurrent_decorator_class.py" - ) - ) - f1, f2 = tflow.tflow(), tflow.tflow() - start = time.time() - await asyncio.gather( - tctx.cycle(sc, f1), - tctx.cycle(sc, f2), - ) - end = time.time() - assert 0.3 < end - start < 0.7