blob: ccae0d315c1cd5eba0c41bdd67c50b2ec5035431 (
plain)
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
60
61
62
63
64
|
from mitmproxy.test import tflow
from mitmproxy.test import tutils
from mitmproxy.test import taddons
from mitmproxy import controller
from mitmproxy.addons import script
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):
with taddons.context() as tctx:
sc = script.Script(
tutils.test_data.path(
"mitmproxy/data/addonscripts/concurrent_decorator.py"
)
)
sc.load(tctx.options)
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")
def test_concurrent_err(self):
with taddons.context() as tctx:
sc = script.Script(
tutils.test_data.path(
"mitmproxy/data/addonscripts/concurrent_decorator_err.py"
)
)
sc.load(tctx.options)
assert tctx.master.has_log("decorator not supported")
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.load(tctx.options)
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")
|