aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-07-14 14:39:07 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-07-14 19:54:15 +1200
commita6821aad8e9296640c3efd4275e8922dd7c6e43b (patch)
tree83ab7d1df26981042e55951b6613dfc80ecf4d9b /test
parenta3a22fba337fc4ac750b8c18663233920a0d646b (diff)
downloadmitmproxy-a6821aad8e9296640c3efd4275e8922dd7c6e43b.tar.gz
mitmproxy-a6821aad8e9296640c3efd4275e8922dd7c6e43b.tar.bz2
mitmproxy-a6821aad8e9296640c3efd4275e8922dd7c6e43b.zip
Zap old scripts infrastructure, fix concurrency tests
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/builtins/test_script.py13
-rw-r--r--test/mitmproxy/data/addonscripts/concurrent_decorator.py (renamed from test/mitmproxy/data/scripts/concurrent_decorator.py)1
-rw-r--r--test/mitmproxy/data/addonscripts/concurrent_decorator_err.py (renamed from test/mitmproxy/data/scripts/concurrent_decorator_err.py)0
-rw-r--r--test/mitmproxy/mastertest.py10
-rw-r--r--test/mitmproxy/script/test_concurrent.py43
5 files changed, 43 insertions, 24 deletions
diff --git a/test/mitmproxy/builtins/test_script.py b/test/mitmproxy/builtins/test_script.py
index d3366189..2447c8ea 100644
--- a/test/mitmproxy/builtins/test_script.py
+++ b/test/mitmproxy/builtins/test_script.py
@@ -47,15 +47,6 @@ def test_load_script():
assert ns["configure"]
-class RecordingMaster(master.FlowMaster):
- def __init__(self, *args, **kwargs):
- master.FlowMaster.__init__(self, *args, **kwargs)
- self.event_log = []
-
- def add_event(self, e, level):
- self.event_log.append((level, e))
-
-
class TestScript(mastertest.MasterTest):
def test_simple(self):
s = state.State()
@@ -77,7 +68,7 @@ class TestScript(mastertest.MasterTest):
def test_reload(self):
s = state.State()
- m = RecordingMaster(options.Options(), None, s)
+ m = mastertest.RecordingMaster(options.Options(), None, s)
with tutils.tmpdir():
with open("foo.py", "w"):
pass
@@ -94,7 +85,7 @@ class TestScript(mastertest.MasterTest):
def test_exception(self):
s = state.State()
- m = RecordingMaster(options.Options(), None, s)
+ m = mastertest.RecordingMaster(options.Options(), None, s)
sc = script.Script(
tutils.test_data.path("data/addonscripts/error.py")
)
diff --git a/test/mitmproxy/data/scripts/concurrent_decorator.py b/test/mitmproxy/data/addonscripts/concurrent_decorator.py
index 162c00f4..a56c2af1 100644
--- a/test/mitmproxy/data/scripts/concurrent_decorator.py
+++ b/test/mitmproxy/data/addonscripts/concurrent_decorator.py
@@ -1,7 +1,6 @@
import time
from mitmproxy.script import concurrent
-
@concurrent
def request(flow):
time.sleep(0.1)
diff --git a/test/mitmproxy/data/scripts/concurrent_decorator_err.py b/test/mitmproxy/data/addonscripts/concurrent_decorator_err.py
index 756869c8..756869c8 100644
--- a/test/mitmproxy/data/scripts/concurrent_decorator_err.py
+++ b/test/mitmproxy/data/addonscripts/concurrent_decorator_err.py
diff --git a/test/mitmproxy/mastertest.py b/test/mitmproxy/mastertest.py
index 9754d3a9..240f6a73 100644
--- a/test/mitmproxy/mastertest.py
+++ b/test/mitmproxy/mastertest.py
@@ -3,6 +3,7 @@ import mock
from . import tutils
import netlib.tutils
+from mitmproxy.flow import master
from mitmproxy import flow, proxy, models, controller
@@ -39,3 +40,12 @@ class MasterTest:
t = tutils.tflow(resp=True)
fw.add(t)
f.close()
+
+
+class RecordingMaster(master.FlowMaster):
+ def __init__(self, *args, **kwargs):
+ master.FlowMaster.__init__(self, *args, **kwargs)
+ self.event_log = []
+
+ def add_event(self, e, level):
+ self.event_log.append((level, e))
diff --git a/test/mitmproxy/script/test_concurrent.py b/test/mitmproxy/script/test_concurrent.py
index 57eeca19..d5243bcb 100644
--- a/test/mitmproxy/script/test_concurrent.py
+++ b/test/mitmproxy/script/test_concurrent.py
@@ -1,28 +1,47 @@
-from mitmproxy.script import Script
from test.mitmproxy import tutils
from mitmproxy import controller
+from mitmproxy.builtins import script
+from mitmproxy import options
+from mitmproxy.flow import master
+from mitmproxy.flow import state
import time
+from .. import mastertest, tutils
class Thing:
def __init__(self):
self.reply = controller.DummyReply()
+ self.live = True
-@tutils.skip_appveyor
-def test_concurrent():
- with Script(tutils.test_data.path("data/scripts/concurrent_decorator.py")) as s:
- f1, f2 = Thing(), Thing()
- s.run("request", f1)
- s.run("request", f2)
+class TestConcurrent(mastertest.MasterTest):
+ @tutils.skip_appveyor
+ def test_concurrent(self):
+ s = state.State()
+ m = master.FlowMaster(options.Options(), None, s)
+ sc = script.Script(
+ tutils.test_data.path(
+ "data/addonscripts/concurrent_decorator.py"
+ )
+ )
+ m.addons.add(sc)
+ f1, f2 = tutils.tflow(), tutils.tflow()
+ self.invoke(m, "request", f1)
+ self.invoke(m, "request", f2)
start = time.time()
while time.time() - start < 5:
if f1.reply.acked and f2.reply.acked:
return
raise ValueError("Script never acked")
-
-def test_concurrent_err():
- s = Script(tutils.test_data.path("data/scripts/concurrent_decorator_err.py"))
- with tutils.raises("Concurrent decorator not supported for 'start' method"):
- s.load()
+ def test_concurrent_err(self):
+ s = state.State()
+ m = mastertest.RecordingMaster(options.Options(), None, s)
+ sc = script.Script(
+ tutils.test_data.path(
+ "data/addonscripts/concurrent_decorator_err.py"
+ )
+ )
+ with m.handlecontext():
+ sc.configure(options.Options())
+ assert "decorator not supported" in m.event_log[0][1]