Skip to content

Fix python 3.10 @ ubuntu pytest ignore #685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-dashboard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
name: Node ${{ matrix.node }} @ ${{ matrix.os }}
strategy:
matrix:
os: [macOS, ubuntu, windows]
os: [ubuntu, windows, macOS]
node: ['10.x', '11.x', '12.x']
max-parallel: 4
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- build
strategy:
matrix:
os: [macOS, Ubuntu]
os: [Ubuntu, macOS]
python: ['3.6', '3.7', '3.8', '3.9', '3.10']
max-parallel: 4
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion proxy/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
DEFAULT_SERVER_RECVBUF_SIZE = DEFAULT_BUFFER_SIZE
DEFAULT_STATIC_SERVER_DIR = os.path.join(PROXY_PY_DIR, "public")
DEFAULT_THREADLESS = False
DEFAULT_TIMEOUT = 10
DEFAULT_TIMEOUT = 10.0
DEFAULT_VERSION = False
DEFAULT_HTTP_PORT = 80
DEFAULT_HTTPS_PORT = 443
Expand Down
2 changes: 1 addition & 1 deletion proxy/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def wrap_socket(


def new_socket_connection(
addr: Tuple[str, int], timeout: int = DEFAULT_TIMEOUT, source_address: Optional[Tuple[str, int]] = None,
addr: Tuple[str, int], timeout: float = DEFAULT_TIMEOUT, source_address: Optional[Tuple[str, int]] = None,
) -> socket.socket:
conn = None
try:
Expand Down
2 changes: 1 addition & 1 deletion proxy/core/acceptor/threadless.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def run(self) -> None:
try:
self.selector = selectors.DefaultSelector()
self.selector.register(self.client_queue, selectors.EVENT_READ)
self.loop = asyncio.get_event_loop()
self.loop = asyncio.get_event_loop_policy().get_event_loop()
while not self.running.is_set():
self.run_once()
except KeyboardInterrupt:
Expand Down
13 changes: 3 additions & 10 deletions proxy/http/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,11 @@ def is_inactive(self) -> bool:

def shutdown(self) -> None:
try:
# Flush pending buffer if any
# TODO: This can block as it register, select, unregister.
# _flush is only for use with threaded mode. In threadless
# mode BaseTcpServerHandler provides must_flush_before_shutdown
# implementation.
# Flush pending buffer in threaded mode only.
# For threadless mode, BaseTcpServerHandler implements
# the must_flush_before_shutdown logic automagically.
if self.selector:
self._flush()
else:
# Call flush for threadless mode assuming client is write ready
# This may fail or block. Using BaseTcpServerHandler will
# solve this issue.
self.client.flush()

# Invoke plugin.on_client_connection_close
for plugin in self.plugins.values():
Expand Down
4 changes: 3 additions & 1 deletion proxy/plugin/cloudflare_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def resolve_dns(self, host: str, port: int) -> Tuple[Optional[str], Optional[Tup
# instead of making a DNS query repeatedly for the same host.
return answers[0]['data'], None
except Exception as e:
logger.exception('Unable to resolve DNS-over-HTTPS', exc_info=e)
logger.info(
'Unable to resolve DNS-over-HTTPS for host {0} : {1}'.format(host, str(e)),
)
return None, None

def before_upstream_connection(
Expand Down
7 changes: 3 additions & 4 deletions proxy/testing/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ def setUpClass(cls) -> None:
@staticmethod
def wait_for_server(
proxy_port: int,
wait_for_seconds: int = DEFAULT_TIMEOUT,
wait_for_seconds: float = DEFAULT_TIMEOUT,
) -> None:
"""Wait for proxy.py server to come up."""
start_time = time.time()
while True:
try:
conn = new_socket_connection(
new_socket_connection(
('localhost', proxy_port),
)
conn.close()
).close()
break
except ConnectionRefusedError:
time.sleep(0.1)
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ filterwarnings =
error

# FIXME: Address the deprecation warning in Python 3.10 and revert this ignore
ignore:There is no current event loop:DeprecationWarning:proxy.core.acceptor.threadless
# ignore:There is no current event loop:DeprecationWarning:proxy.core.acceptor.threadless
Copy link
Contributor

@webknjaz webknjaz Nov 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why didn't you just delete these lines? Ideally, only error should remain.

Copy link
Owner Author

@abhinavsingh abhinavsingh Nov 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally, I initially didn't delete coz I wasn't confident if this would work. Later i missed removing them altogether before merge. Will remove within README PR now :)


junit_duration_report = call
# xunit1 contains more metadata than xunit2 so it's better for CI UIs:
Expand Down
26 changes: 18 additions & 8 deletions tests/test_circular_imports.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
"""Tests for circular imports in all local packages and modules.
# -*- coding: utf-8 -*-
Copy link
Contributor

@webknjaz webknjaz Nov 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Need to also deprecate text_ and bytes_ hell and replace with encode / decode.

I have a pre-commit hook locally which ensures this line + license on top of all python files. May be I should commit it and add to workflows now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have a local hook in the pre-commit config.

"""
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on
Network monitoring, controls & Application development, testing, debugging.

:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.

Tests for circular imports in all local packages and modules.

This ensures all internal packages can be imported right away without
any need to import some other module before doing so.
This ensures all internal packages can be imported right away without
any need to import some other module before doing so.

This module is based on an idea that pytest uses for self-testing:
* https://github.com/sanitizers/octomachinery/blob/be18b54/tests/circular_imports_test.py
* https://github.com/pytest-dev/pytest/blob/d18c75b/testing/test_meta.py
* https://twitter.com/codewithanthony/status/1229445110510735361
This module is based on an idea that pytest uses for self-testing:
* https://github.com/sanitizers/octomachinery/blob/be18b54/tests/circular_imports_test.py
* https://github.com/pytest-dev/pytest/blob/d18c75b/testing/test_meta.py
* https://twitter.com/codewithanthony/status/1229445110510735361
"""
from itertools import chain
from pathlib import Path
from types import ModuleType
from typing import Generator, List

import os
import pkgutil
import subprocess
import sys

import pytest

import proxy
Expand Down
4 changes: 2 additions & 2 deletions tests/testing/test_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

class TestTestCase(unittest.TestCase):

def test_wait_for_server(self) -> None:
def test_wait_for_server_raises_timeout_error(self) -> None:
with self.assertRaises(TimeoutError):
proxy.TestCase.wait_for_server(
get_available_port(), wait_for_seconds=1,
get_available_port(), wait_for_seconds=0.1,
)