diff options
author | Miheer Dewaskar <miheerdew@gmail.com> | 2018-03-24 10:49:08 -0400 |
---|---|---|
committer | Miheer Dewaskar <miheerdew@gmail.com> | 2018-03-24 10:49:08 -0400 |
commit | 9ee96f022764c71a4a776956037230d6ef4fee7e (patch) | |
tree | 8ebae8b64fcc0474466b3321efec201416d75ed0 /test | |
parent | 00d51db9250bedf8a36924e15345648b0cecc38f (diff) | |
parent | 2859ee2fa8c7f3311c069a40ada3975d31e8eccf (diff) | |
download | mitmproxy-9ee96f022764c71a4a776956037230d6ef4fee7e.tar.gz mitmproxy-9ee96f022764c71a4a776956037230d6ef4fee7e.tar.bz2 mitmproxy-9ee96f022764c71a4a776956037230d6ef4fee7e.zip |
Merge master
Diffstat (limited to 'test')
-rw-r--r-- | test/bench/.gitignore | 1 | ||||
-rw-r--r-- | test/bench/README.md | 56 | ||||
-rwxr-xr-x | test/bench/backend | 3 | ||||
-rw-r--r-- | test/bench/profiler.py | 25 | ||||
-rwxr-xr-x | test/bench/simple.mitmproxy | 5 | ||||
-rwxr-xr-x | test/bench/simple.traffic | 3 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_onboarding.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/test_command.py | 25 | ||||
-rw-r--r-- | test/mitmproxy/test_connections.py | 6 | ||||
-rw-r--r-- | test/mitmproxy/utils/test_human.py | 1 |
10 files changed, 129 insertions, 0 deletions
diff --git a/test/bench/.gitignore b/test/bench/.gitignore new file mode 100644 index 00000000..1a06816d --- /dev/null +++ b/test/bench/.gitignore @@ -0,0 +1 @@ +results diff --git a/test/bench/README.md b/test/bench/README.md new file mode 100644 index 00000000..05741c07 --- /dev/null +++ b/test/bench/README.md @@ -0,0 +1,56 @@ + +This directory contains a set of tools for benchmarking and profiling mitmproxy. +At the moment, this is simply to give developers a quick way to see the impact +of their work. Eventually, this might grow into a performance dashboard with +historical data, so we can track performance over time. + + +# Setup + +Install the following tools: + + go get -u github.com/rakyll/hey + go get github.com/cortesi/devd/cmd/devd + +You may also want to install snakeviz to make viewing profiles easier: + + pip install snakeviz + +In one window, run the devd server: + + ./backend + + +# Running tests + +Each run consists of two files - a mitproxy invocation, and a traffic generator. +Make sure the backend is started, then run the proxy: + + ./simple.mitmproxy + +Now run the traffic generator: + + ./simple.traffic + +After the run is done, quit the proxy with ctrl-c. + + +# Reading results + +Results are placed in the ./results directory. You should see two files - a +performance log from **hey**, and a profile. You can view the profile like so: + + snakeviz ./results/simple.prof + + + + + + + + + + + + + diff --git a/test/bench/backend b/test/bench/backend new file mode 100755 index 00000000..12a05d70 --- /dev/null +++ b/test/bench/backend @@ -0,0 +1,3 @@ +#!/bin/sh + +devd -p 10001 .
\ No newline at end of file diff --git a/test/bench/profiler.py b/test/bench/profiler.py new file mode 100644 index 00000000..9072e17d --- /dev/null +++ b/test/bench/profiler.py @@ -0,0 +1,25 @@ +import cProfile +from mitmproxy import ctx + + +class Profile: + """ + A simple profiler addon. + """ + def __init__(self): + self.pr = cProfile.Profile() + + def load(self, loader): + loader.add_option( + "profile_path", + str, + "/tmp/profile", + "Destination for the run profile, saved at exit" + ) + self.pr.enable() + + def done(self): + self.pr.dump_stats(ctx.options.profile_path) + + +addons = [Profile()]
\ No newline at end of file diff --git a/test/bench/simple.mitmproxy b/test/bench/simple.mitmproxy new file mode 100755 index 00000000..9de32981 --- /dev/null +++ b/test/bench/simple.mitmproxy @@ -0,0 +1,5 @@ +#!/bin/sh + +mkdir -p results +mitmdump -p 10002 --mode reverse:http://devd.io:10001 \ + -s ./profiler.py --set profile_path=./results/simple.prof diff --git a/test/bench/simple.traffic b/test/bench/simple.traffic new file mode 100755 index 00000000..08200e05 --- /dev/null +++ b/test/bench/simple.traffic @@ -0,0 +1,3 @@ +#!/bin/sh + +hey -disable-keepalive http://localhost:10002/profiler.py | tee ./results/simple.perf
\ No newline at end of file diff --git a/test/mitmproxy/addons/test_onboarding.py b/test/mitmproxy/addons/test_onboarding.py index 810ddef1..0d99b1ff 100644 --- a/test/mitmproxy/addons/test_onboarding.py +++ b/test/mitmproxy/addons/test_onboarding.py @@ -4,6 +4,10 @@ from mitmproxy.addons import onboarding from mitmproxy.test import taddons from .. import tservers +import asyncio +import tornado.platform.asyncio +asyncio.set_event_loop_policy(tornado.platform.asyncio.AnyThreadEventLoopPolicy()) + class TestApp(tservers.HTTPProxyTest): def addons(self): diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index e2b80753..3d0a43f8 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -309,6 +309,31 @@ class TDec: pass +class TAttr: + def __getattr__(self, item): + raise IOError + + +class TCmds(TAttr): + def __init__(self): + self.TAttr = TAttr() + + @command.command("empty") + def empty(self) -> None: + pass + + +def test_collect_commands(): + """ + This tests for the error thrown by hasattr() + """ + with taddons.context() as tctx: + c = command.CommandManager(tctx.master) + a = TCmds() + c.collect_commands(a) + assert "empty" in c.commands + + def test_decorator(): with taddons.context() as tctx: c = command.CommandManager(tctx.master) diff --git a/test/mitmproxy/test_connections.py b/test/mitmproxy/test_connections.py index 00cdbc87..845a9043 100644 --- a/test/mitmproxy/test_connections.py +++ b/test/mitmproxy/test_connections.py @@ -38,6 +38,9 @@ class TestClientConnection: assert 'ALPN' not in repr(c) assert 'TLS' in repr(c) + c.address = None + assert repr(c) + def test_tls_established_property(self): c = tflow.tclient_conn() c.tls_established = True @@ -110,6 +113,9 @@ class TestServerConnection: c.tls_established = False assert 'TLS' not in repr(c) + c.address = None + assert repr(c) + def test_tls_established_property(self): c = tflow.tserver_conn() c.tls_established = True diff --git a/test/mitmproxy/utils/test_human.py b/test/mitmproxy/utils/test_human.py index 947cfa4a..faf35f72 100644 --- a/test/mitmproxy/utils/test_human.py +++ b/test/mitmproxy/utils/test_human.py @@ -56,3 +56,4 @@ def test_format_address(): assert human.format_address(("example.com", "54010")) == "example.com:54010" assert human.format_address(("::", "8080")) == "*:8080" assert human.format_address(("0.0.0.0", "8080")) == "*:8080" + assert human.format_address(None) == "<no address>" |