1616from hippolyzer .lib .proxy .addon_utils import BaseAddon
1717from hippolyzer .lib .proxy .addons import AddonManager
1818from hippolyzer .lib .proxy .http_event_manager import MITMProxyEventManager
19+ from hippolyzer .lib .proxy .http_proxy import HTTPFlowContext
1920from hippolyzer .lib .proxy .http_flow import HippoHTTPFlow
2021from hippolyzer .lib .proxy .caps import SerializedCapData
2122from hippolyzer .lib .proxy .sessions import SessionManager
@@ -35,6 +36,7 @@ async def asyncSetUp(self) -> None:
3536 await super ().asyncSetUp ()
3637 self .addon = MockAddon ()
3738 AddonManager .init ([], self .session_manager , [self .addon ])
39+ self .session_manager .flow_context = HTTPFlowContext ()
3840 self .flow_context = self .session_manager .flow_context
3941 self .http_event_manager = MITMProxyEventManager (self .session_manager , self .flow_context )
4042 self ._setup_default_circuit ()
@@ -148,6 +150,7 @@ async def asyncSetUp(self) -> None:
148150 self .caps_client = self .session .main_region .caps_client
149151 proxy_port = 9905
150152 self .session_manager .settings .HTTP_PROXY_PORT = proxy_port
153+ self .session_manager .flow_context = HTTPFlowContext ()
151154
152155 self .http_proc = multiprocessing .Process (
153156 target = run_http_proxy_process ,
@@ -162,6 +165,15 @@ async def asyncSetUp(self) -> None:
162165 self .session_manager .flow_context
163166 )
164167
168+ def tearDown (self ) -> None :
169+ self .session_manager .flow_context .shutdown_signal .set ()
170+ self .http_proc .join (timeout = 2.0 )
171+ if self .http_proc .is_alive ():
172+ self .http_proc .terminate ()
173+ self .http_proc .join (timeout = 1.0 )
174+ self .http_proc .close ()
175+ super ().tearDown ()
176+
165177 def test_mitmproxy_works (self ):
166178 async def _request_example_com ():
167179 # Pump callbacks from mitmproxy
0 commit comments