parent
c9ce446440
commit
ae92adc432
|
@ -809,10 +809,12 @@ Note that:
|
|||
|
||||
1. `proxy.TestCase` overrides `unittest.TestCase.run()` method to setup and teardown `proxy.py`.
|
||||
2. `proxy.py` server will listen on a random available port on the system.
|
||||
This random port is available as `self.proxy_port` within your test cases.
|
||||
This random port is available as `self.PROXY_PORT` within your test cases.
|
||||
3. Only a single worker is started by default (`--num-workers 1`) for faster setup and teardown.
|
||||
4. Most importantly, `proxy.TestCase` also ensures `proxy.py` server
|
||||
is up and running before proceeding with execution of tests.
|
||||
is up and running before proceeding with execution of tests. By default,
|
||||
`proxy.TestCase` will wait for `10 seconds` for `proxy.py` server to start,
|
||||
upon failure a `TimeoutError` exception will be raised.
|
||||
|
||||
## Override startup flags
|
||||
|
||||
|
@ -857,6 +859,9 @@ class TestProxyPyEmbedded(unittest.TestCase):
|
|||
super().run(result)
|
||||
```
|
||||
|
||||
or simply setup / teardown `proxy.py` within
|
||||
`setUpClass` and `teardownClass` class methods.
|
||||
|
||||
Plugin Developer and Contributor Guide
|
||||
======================================
|
||||
|
||||
|
|
|
@ -46,7 +46,8 @@ class BaseCacheResponsesPlugin(HttpProxyBasePlugin):
|
|||
logger.info('Caching disabled due to exception message %s', str(e))
|
||||
return request
|
||||
|
||||
def handle_client_request(self, request: HttpParser) -> Optional[HttpParser]:
|
||||
def handle_client_request(
|
||||
self, request: HttpParser) -> Optional[HttpParser]:
|
||||
assert self.store
|
||||
return self.store.cache_request(request)
|
||||
|
||||
|
|
|
@ -24,5 +24,6 @@ class CacheResponsesPlugin(BaseCacheResponsesPlugin):
|
|||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
self.disk_store = OnDiskCacheStore(uid=self.uid, cache_dir=tempfile.gettempdir())
|
||||
self.disk_store = OnDiskCacheStore(
|
||||
uid=self.uid, cache_dir=tempfile.gettempdir())
|
||||
self.set_store(self.disk_store)
|
||||
|
|
|
@ -48,7 +48,8 @@ class TestCase(unittest.TestCase):
|
|||
cls.wait_for_server(cls.PROXY_PORT)
|
||||
|
||||
@staticmethod
|
||||
def wait_for_server(proxy_port: int, wait_for_seconds: int = DEFAULT_TIMEOUT) -> None:
|
||||
def wait_for_server(proxy_port: int,
|
||||
wait_for_seconds: int = DEFAULT_TIMEOUT) -> None:
|
||||
"""Wait for proxy.py server to come up."""
|
||||
start_time = time.time()
|
||||
while True:
|
||||
|
@ -61,7 +62,8 @@ class TestCase(unittest.TestCase):
|
|||
time.sleep(0.1)
|
||||
|
||||
if time.time() - start_time > wait_for_seconds:
|
||||
raise TimeoutError('Timed out while waiting for proxy.py to start...')
|
||||
raise TimeoutError(
|
||||
'Timed out while waiting for proxy.py to start...')
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls) -> None:
|
||||
|
|
|
@ -18,4 +18,5 @@ class TestTestCase(unittest.TestCase):
|
|||
|
||||
def test_wait_for_server(self) -> None:
|
||||
with self.assertRaises(TimeoutError):
|
||||
proxy.TestCase.wait_for_server(get_available_port(), wait_for_seconds=1)
|
||||
proxy.TestCase.wait_for_server(
|
||||
get_available_port(), wait_for_seconds=1)
|
||||
|
|
Loading…
Reference in New Issue