/
test_concurrent.py
59 lines (50 loc) · 1.78 KB
/
test_concurrent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pytest
from mitmproxy.test import tflow
from mitmproxy.test import taddons
from mitmproxy import controller
import time
from .. import tservers
class Thing:
def __init__(self):
self.reply = controller.DummyReply()
self.live = True
class TestConcurrent(tservers.MasterTest):
def test_concurrent(self, tdata):
with taddons.context() as tctx:
sc = tctx.script(
tdata.path(
"mitmproxy/data/addonscripts/concurrent_decorator.py"
)
)
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")
@pytest.mark.asyncio
async def test_concurrent_err(self, tdata):
with taddons.context() as tctx:
tctx.script(
tdata.path(
"mitmproxy/data/addonscripts/concurrent_decorator_err.py"
)
)
assert await tctx.master.await_log("decorator not supported")
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()
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")