Skip to content

Commit d192046

Browse files
Pre v2.4.0rc8 cleanups (#1053)
* Pre-release cleanups * Add listener pool test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add multi listener test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2bebbac commit d192046

File tree

11 files changed

+131
-70
lines changed

11 files changed

+131
-70
lines changed

benchmark/_proxy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
open_file_limit=65536,
2424
enable_web_server=True,
2525
disable_proxy_server=True,
26-
num_acceptors=10,
27-
local_executor=1,
26+
num_acceptors=4,
27+
num_workers=10,
28+
local_executor=0,
2829
log_file='/dev/null',
2930
) as _:
3031
while True:

examples/task.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ def start_remote_pool(flags: argparse.Namespace) -> None:
110110
pass
111111

112112

113+
# TODO: TaskWork, LocalTaskExecutor, RemoteTaskExecutor
114+
# should not be needed, abstract those pieces out in the core
115+
# for stateless tasks.
113116
if __name__ == '__main__':
114117
flags = FlagParser.initialize(
115118
['--disable-http-proxy'],

proxy/core/listener/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from .unix import UnixSocketListener
1616

1717

18-
if TYPE_CHECKING:
18+
if TYPE_CHECKING: # pragma: no cover
1919
from .base import BaseListener
2020

2121

proxy/core/work/fd/fd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def work(self, *args: Any) -> None:
4545
self.works[fileno].initialize()
4646
self._total += 1
4747
except Exception as e:
48-
logger.exception(
48+
logger.exception( # pragma: no cover
4949
'Exception occurred during initialization',
5050
exc_info=e,
5151
)

proxy/http/server/reverse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626

2727

28-
if TYPE_CHECKING:
28+
if TYPE_CHECKING: # pragma: no cover
2929
from .plugin import ReverseProxyBasePlugin
3030

3131

@@ -92,7 +92,7 @@ def handle_request(self, request: HttpParser) -> None:
9292
# )
9393
self.upstream.queue(memoryview(request.build()))
9494
except ConnectionRefusedError:
95-
raise HttpProtocolException(
95+
raise HttpProtocolException( # pragma: no cover
9696
'Connection refused by upstream server {0}:{1}'.format(
9797
text_(self.choice.hostname), port,
9898
),

proxy/plugin/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626
from .custom_dns_resolver import CustomDnsResolverPlugin
2727
from .filter_by_client_ip import FilterByClientIpPlugin
2828
from .filter_by_url_regex import FilterByURLRegexPlugin
29-
from .cache_by_content_type import CacheByContentTypePlugin
3029
from .modify_chunk_response import ModifyChunkResponsePlugin
3130
from .redirect_to_custom_server import RedirectToCustomServerPlugin
3231

3332

3433
__all__ = [
3534
'CacheResponsesPlugin',
36-
'CacheByContentTypePlugin',
3735
'BaseCacheResponsesPlugin',
3836
'FilterByUpstreamHostPlugin',
3937
'ManInTheMiddlePlugin',

proxy/plugin/cache_by_content_type.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

proxy/proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
)
3333

3434

35-
if TYPE_CHECKING:
35+
if TYPE_CHECKING: # pragma: no cover
3636
from .core.listener import TcpSocketListener
3737

3838

proxy/socks/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
2222

2323
@staticmethod
2424
def create(*args: Any) -> SocksClientConnection:
25-
return SocksClientConnection(*args)
25+
return SocksClientConnection(*args) # pragma: no cover
2626

2727
def handle_data(self, data: memoryview) -> Optional[bool]:
28-
return super().handle_data(data)
28+
return super().handle_data(data) # pragma: no cover

tests/core/test_listener.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,31 @@ class TestListener(unittest.TestCase):
2727
def test_setup_and_teardown(self, mock_socket: mock.Mock) -> None:
2828
sock = mock_socket.return_value
2929
flags = FlagParser.initialize(port=0)
30-
listener = TcpSocketListener(flags=flags)
31-
listener.setup()
32-
mock_socket.assert_called_with(
33-
socket.AF_INET6 if flags.hostname.version == 6 else socket.AF_INET,
34-
socket.SOCK_STREAM,
35-
)
36-
self.assertEqual(sock.setsockopt.call_count, 2)
37-
self.assertEqual(
38-
sock.setsockopt.call_args_list[0][0],
39-
(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
40-
)
41-
self.assertEqual(
42-
sock.setsockopt.call_args_list[1][0],
43-
(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),
44-
)
45-
sock.bind.assert_called_with(
46-
(str(flags.hostname), 0),
47-
)
48-
sock.listen.assert_called_with(flags.backlog)
49-
sock.setblocking.assert_called_with(False)
50-
51-
listener.shutdown()
30+
with TcpSocketListener(flags=flags) as listener:
31+
mock_socket.assert_called_with(
32+
socket.AF_INET6 if flags.hostname.version == 6 else socket.AF_INET,
33+
socket.SOCK_STREAM,
34+
)
35+
self.assertEqual(sock.setsockopt.call_count, 2)
36+
self.assertEqual(
37+
sock.setsockopt.call_args_list[0][0],
38+
(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
39+
)
40+
self.assertEqual(
41+
sock.setsockopt.call_args_list[1][0],
42+
(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),
43+
)
44+
sock.bind.assert_called_with(
45+
(str(flags.hostname), 0),
46+
)
47+
sock.listen.assert_called_with(flags.backlog)
48+
sock.setblocking.assert_called_with(False)
49+
self.assertEqual(
50+
listener.fileno(),
51+
mock_socket.return_value.fileno.return_value,
52+
)
5253
sock.close.assert_called_once()
5354

54-
# FIXME: Ignore is necessary for as long as pytest hasn't figured out
55-
# FIXME: typing for their fixtures.
56-
# Refs:
57-
# * https://github.com/pytest-dev/pytest/issues/7469#issuecomment-918345196
58-
# * https://github.com/pytest-dev/pytest/issues/3342
5955
@pytest.mark.skipif(
6056
IS_WINDOWS,
6157
reason='AF_UNIX not available on Windows',

0 commit comments

Comments
 (0)