Skip to content

[Tests] test_static_web_server_serves fails rare scenarios #374

Closed
@abhinavsingh

Description

@abhinavsingh

Just saw this error on Ubuntu (VirtualBox), re-running the tests made it work. Unable to reproduce. Opening this bug for future investigations.

To Reproduce
Steps to reproduce the behavior:

  1. make to run tests
  2. Occasionally static web server serves test fails
======================================================================== FAILURES ========================================================================
___________________________________________________ TestWebServerPlugin.test_static_web_server_serves ____________________________________________________

self = <tests.http.test_web_server.TestWebServerPlugin testMethod=test_static_web_server_serves>
mock_fromfd = <MagicMock name='fromfd' id='139640519119704'>, mock_selector = <MagicMock name='DefaultSelector' id='139640519023864'>

    @unittest.skipIf(os.environ.get('GITHUB_ACTIONS', False),
                     'Disabled on GitHub actions because this test is flaky on GitHub infrastructure.')
    @mock.patch('selectors.DefaultSelector')
    @mock.patch('socket.fromfd')
    def test_static_web_server_serves(
            self, mock_fromfd: mock.Mock, mock_selector: mock.Mock) -> None:
        # Setup a static directory
        static_server_dir = os.path.join(tempfile.gettempdir(), 'static')
        index_file_path = os.path.join(static_server_dir, 'index.html')
        html_file_content = b'''<html><head></head><body><h1>Proxy.py Testing</h1></body></html>'''
        os.makedirs(static_server_dir, exist_ok=True)
        with open(index_file_path, 'wb') as f:
            f.write(html_file_content)
    
        self._conn = mock_fromfd.return_value
        self._conn.recv.return_value = build_http_request(
            b'GET', b'/index.html')
    
        mock_selector.return_value.select.side_effect = [
            [(selectors.SelectorKey(
                fileobj=self._conn,
                fd=self._conn.fileno,
                events=selectors.EVENT_READ,
                data=None), selectors.EVENT_READ)],
            [(selectors.SelectorKey(
                fileobj=self._conn,
                fd=self._conn.fileno,
                events=selectors.EVENT_WRITE,
                data=None), selectors.EVENT_WRITE)], ]
    
        flags = Flags(
            enable_static_server=True,
            static_server_dir=static_server_dir)
        flags.plugins = Flags.load_plugins(
            b'proxy.http.proxy.HttpProxyPlugin,proxy.http.server.HttpWebServerPlugin')
    
        self.protocol_handler = HttpProtocolHandler(
            TcpClientConnection(self._conn, self._addr),
            flags=flags)
        self.protocol_handler.initialize()
    
        self.protocol_handler.run_once()
        self.protocol_handler.run_once()
    
        self.assertEqual(mock_selector.return_value.select.call_count, 2)
        self.assertEqual(self._conn.send.call_count, 1)
        encoded_html_file_content = gzip.compress(html_file_content)
        self.assertEqual(self._conn.send.call_args[0][0], build_http_response(
            200, reason=b'OK', headers={
                b'Content-Type': b'text/html',
                b'Cache-Control': b'max-age=86400',
                b'Content-Encoding': b'gzip',
                b'Connection': b'close',
                b'Content-Length': bytes_(len(encoded_html_file_content)),
            },
>           body=encoded_html_file_content
        ))
E       AssertionError: b"HTT[162 chars]00\xec\xca\xe9^\x02\xff\xb3\xc9(\xc9\xcd\xb1\x[152 chars]\x00" != b"HTT[162 chars]00\xed\xca\xe9^\x02\xff\xb3\xc9(\xc9\xcd\xb1\x[152 chars]\x00"

tests/http/test_web_server.py:171: AssertionError

Version information

  • OS: Ubuntu (VirtualBox)
  • Version: develop

Metadata

Metadata

Assignees

Labels

BugBug report in proxy serverLinuxIssues found only on Linux OS

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions