-
Notifications
You must be signed in to change notification settings - Fork 143
Pin uvloop<0.22 and add sanity test for it #7432
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
Open
pedro-psb
wants to merge
3
commits into
pulp:main
Choose a base branch
from
pedro-psb:pin-uvloop-and-add-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+111
−4
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Pinned uvloop (optional dependency) to prevent a known bug in a newer releases. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| import pytest | ||
| from uuid import uuid4 | ||
|
|
||
| from pulpcore.app.models import Domain | ||
| from pulpcore.app.util import set_domain | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def fake_domain(): | ||
| """A fixture to prevent `get_domain` to call out to the database.""" | ||
| from pulpcore.app.models import Domain | ||
| from pulpcore.app.util import set_domain | ||
|
|
||
| set_domain(Domain(pk=uuid4(), name=uuid4())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| """App startup scenarios which doesn't require a full instance.""" | ||
|
|
||
| import base64 | ||
| import os | ||
| import secrets | ||
| import subprocess | ||
| from textwrap import dedent | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def pulpcore_source_dir() -> Path: | ||
| """The pulpcore source directory (repository root).""" | ||
| source_dir = Path(__file__).parents[3] | ||
| lookup_dirs = ( | ||
| Path(__file__).parents[3], | ||
| Path("/pulpcore"), | ||
| Path("/src/pulpcore"), | ||
| ) | ||
| source_dir = None | ||
| for dir in lookup_dirs: | ||
| if (dir / "pyproject.toml").exists(): | ||
| source_dir = dir | ||
| break | ||
| if not source_dir: | ||
| raise RuntimeError("Couldn't find pulpcore's source") | ||
| return source_dir | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def pulpcore_dist(pulpcore_source_dir) -> Path | None: | ||
| pulpcore_dist_glob = list((pulpcore_source_dir / "dist").glob("*.whl")) | ||
| pulpcore_dist = pulpcore_dist_glob[0] if len(pulpcore_dist_glob) else None | ||
| return pulpcore_dist | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def encryption_key_file(tmp_path: Path) -> Path: | ||
| """A file with a symmetric encryption key.""" | ||
| key_file = tmp_path / "symmetric.key" | ||
| key = base64.urlsafe_b64encode(secrets.token_bytes(32)) | ||
| key_file.write_bytes(key) | ||
| return key_file | ||
|
|
||
|
|
||
| class TestUvloop: | ||
| def test_uvloop_startup( | ||
| self, pulpcore_source_dir: Path, pulpcore_dist: Path | None, pulp_env: dict[str, str] | ||
| ): | ||
| """ | ||
| Test that pulpcore-content can start successfully with uvloop enabled. | ||
| """ | ||
| TIMEOUT_PROGRAM_EXIT_CODE = 124 # means 'timeout N' exited after N seconds | ||
| ci_constraints = pulpcore_source_dir / ".ci" / "assets" / "ci_constraints.txt" | ||
| install_source = pulpcore_dist or pulpcore_source_dir | ||
|
|
||
| cmd = [ | ||
| "uv", | ||
| "run", | ||
| "--isolated", | ||
| "--no-project", | ||
| "--with", | ||
| f"{str(install_source.resolve())}[uvloop]", | ||
| "--with-requirements", | ||
| str(ci_constraints.resolve()), | ||
| "timeout", | ||
| "5", | ||
| "pulpcore-content", | ||
| "--bind", | ||
| "127.0.0.1:0", # Use random available port | ||
| ] | ||
|
|
||
| result = subprocess.run(cmd, env=pulp_env, capture_output=True) | ||
|
|
||
| stderr = result.stderr.decode() | ||
| assert result.returncode == TIMEOUT_PROGRAM_EXIT_CODE, ( | ||
| f"pulpcore-content exited prematurely with exit code {result.returncode}.\n" | ||
| f"Output: {stderr}" | ||
| ) | ||
| assert "Using uvloop as the asyncio event loop" in stderr | ||
| assert ( | ||
| "Connection in use:" not in stderr | ||
| ), "Some other program is using the port shown in stderr" | ||
|
|
||
| @pytest.fixture | ||
| def settings_file(self, tmp_path: Path, encryption_key_file: Path) -> Path: | ||
| settings_file = tmp_path / "settings.py" | ||
| settings_content = f""" | ||
| UVLOOP_ENABLED = True | ||
| FILE_UPLOAD_TEMP_DIR = "{tmp_path.resolve()}" | ||
| WORKING_DIRECTORY = "{tmp_path.resolve()}" | ||
| DB_ENCRYPTION_KEY = "{encryption_key_file.resolve()}" | ||
| """ | ||
| settings_file.write_text(dedent(settings_content)) | ||
| return settings_file | ||
|
|
||
| @pytest.fixture | ||
| def pulp_env(self, settings_file: Path) -> dict[str, str]: | ||
| """Configured environment.""" | ||
| env = {} | ||
| env["PATH"] = os.environ["PATH"] # enable subprocess to find system binaries | ||
| env["PULP_SETTINGS"] = str(settings_file) | ||
| return env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By lazy importing this we avoid triggering django machinery, which makes it easier to run unit tests directly from the host (which is what I did for this test).