aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2018-04-16 10:16:51 +1200
committerAldo Cortesi <aldo@corte.si>2018-04-16 10:16:51 +1200
commit565146311a5f7939f107af12a91d94f5f96d56fc (patch)
tree3eae65bfb213e549531fa21dfb4edb4e8ce58410 /test
parent850c855495d29f24e3c51af582b6b4448433ae69 (diff)
downloadmitmproxy-565146311a5f7939f107af12a91d94f5f96d56fc.tar.gz
mitmproxy-565146311a5f7939f107af12a91d94f5f96d56fc.tar.bz2
mitmproxy-565146311a5f7939f107af12a91d94f5f96d56fc.zip
asyncio: clarify shutdown semantics
This patch clarifies proxy shutdown, and specifies that the master.shutdown() method is thread-save.
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_keepserving.py7
-rw-r--r--test/mitmproxy/data/addonscripts/shutdown.py5
-rw-r--r--test/mitmproxy/tools/test_main.py19
-rw-r--r--test/mitmproxy/tservers.py2
4 files changed, 13 insertions, 20 deletions
diff --git a/test/mitmproxy/addons/test_keepserving.py b/test/mitmproxy/addons/test_keepserving.py
index 2869d097..5eafa792 100644
--- a/test/mitmproxy/addons/test_keepserving.py
+++ b/test/mitmproxy/addons/test_keepserving.py
@@ -1,9 +1,14 @@
+import asyncio
+import pytest
+
from mitmproxy.addons import keepserving
from mitmproxy.test import taddons
-def test_keepserving():
+@pytest.mark.asyncio
+async def test_keepserving():
ks = keepserving.KeepServing()
with taddons.context(ks) as tctx:
ks.event_processing_complete()
+ asyncio.sleep(0.1)
assert tctx.master.should_exit.is_set()
diff --git a/test/mitmproxy/data/addonscripts/shutdown.py b/test/mitmproxy/data/addonscripts/shutdown.py
deleted file mode 100644
index 3da4d03e..00000000
--- a/test/mitmproxy/data/addonscripts/shutdown.py
+++ /dev/null
@@ -1,5 +0,0 @@
-from mitmproxy import ctx
-
-
-def tick():
- ctx.master.shutdown()
diff --git a/test/mitmproxy/tools/test_main.py b/test/mitmproxy/tools/test_main.py
index a514df74..ba213733 100644
--- a/test/mitmproxy/tools/test_main.py
+++ b/test/mitmproxy/tools/test_main.py
@@ -1,25 +1,18 @@
import pytest
-from mitmproxy.test import tutils
from mitmproxy.tools import main
-shutdown_script = tutils.test_data.path("mitmproxy/data/addonscripts/shutdown.py")
-
@pytest.mark.asyncio
-async def test_mitmweb():
- main.mitmweb([
+async def test_mitmweb(event_loop):
+ m = main.mitmweb([
"--no-web-open-browser",
- "-q",
- "-p", "0",
- "-s", shutdown_script
+ "-q", "-p", "0",
])
+ await m._shutdown()
@pytest.mark.asyncio
async def test_mitmdump():
- main.mitmdump([
- "-q",
- "-p", "0",
- "-s", shutdown_script
- ])
+ m = main.mitmdump(["-q", "-p", "0"])
+ await m._shutdown()
diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py
index 13ee4a43..857ca45d 100644
--- a/test/mitmproxy/tservers.py
+++ b/test/mitmproxy/tservers.py
@@ -40,7 +40,7 @@ class MasterTest:
async def dummy_cycle(self, master, n, content):
for i in range(n):
await self.cycle(master, content)
- master.shutdown()
+ await master._shutdown()
def flowfile(self, path):
with open(path, "wb") as f: