mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 07:08:10 +00:00
simplify concurrency tests
This commit is contained in:
parent
068204fc59
commit
4f5930ec5d
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user