From 148721c880ae2de26f7d8679b024804007b1215c Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Sat, 10 Aug 2024 09:23:22 +0530 Subject: [PATCH] Fix `test_pac_file_served_from_disk` --- proxy/http/handler.py | 4 +--- tests/http/web/test_web_server.py | 39 ++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/proxy/http/handler.py b/proxy/http/handler.py index 0bdcfa22c0..5120d5b32c 100644 --- a/proxy/http/handler.py +++ b/proxy/http/handler.py @@ -292,9 +292,7 @@ def _parse_first_request(self, data: memoryview) -> bool: return True # Discover which HTTP handler plugin is capable of # handling the current incoming request - klass = self._discover_plugin_klass( - self.request.http_handler_protocol, - ) + klass = self._discover_plugin_klass(self.request.http_handler_protocol) if klass is None: # No matching protocol class found. # Return bad request response and diff --git a/tests/http/web/test_web_server.py b/tests/http/web/test_web_server.py index e7b2e7aa47..bcd338339d 100644 --- a/tests/http/web/test_web_server.py +++ b/tests/http/web/test_web_server.py @@ -59,19 +59,6 @@ def test_on_client_connection_called_on_teardown(mocker: MockerFixture) -> None: assert _conn.closed -def mock_selector_for_client_read(self: Any) -> None: - self.mock_selector.return_value.select.return_value = [ - ( - selectors.SelectorKey( - fileobj=self._conn.fileno(), - fd=self._conn.fileno(), - events=selectors.EVENT_READ, - data=None, - ), - selectors.EVENT_READ, - ), - ] - # @mock.patch('socket.fromfd') # def test_on_client_connection_called_on_teardown( # self, mock_fromfd: mock.Mock, @@ -171,10 +158,34 @@ def _setUp(self, request: Any, mocker: MockerFixture) -> None: b'GET / HTTP/1.1', CRLF, ]) - mock_selector_for_client_read(self) + self.mock_selector.return_value.select.side_effect = [ + [ + ( + selectors.SelectorKey( + fileobj=self._conn.fileno(), + fd=self._conn.fileno(), + events=selectors.EVENT_READ, + data=None, + ), + selectors.EVENT_READ, + ) + ], + [ + ( + selectors.SelectorKey( + fileobj=self._conn.fileno(), + fd=self._conn.fileno(), + events=selectors.EVENT_WRITE, + data=None, + ), + selectors.EVENT_WRITE, + ) + ], + ] @pytest.mark.asyncio # type: ignore[misc] async def test_pac_file_served_from_disk(self) -> None: + await self.protocol_handler._run_once() await self.protocol_handler._run_once() self.assertEqual( self.protocol_handler.request.state,