-
Notifications
You must be signed in to change notification settings - Fork 72
perf(tests): move SQL worker schema setup to session scope #369
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0b9db81
perf(tests): move SQL worker schema setup to session scope (#361)
Borda ae19ad1
docs(tests): clarify DB schema fixture behavior and improve logging f…
Borda 56e115d
test(tests): add unit tests for private conftest helpers `_worker_sch…
Borda 06c69a8
docs(tests): add detailed docstrings to `_worker_schema_name` and `_b…
Borda 64a0b71
Apply suggestions from code review
Borda 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
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,54 @@ | ||
| """Unit tests for private helpers in tests/conftest.py.""" | ||
|
|
||
| from tests.conftest import _build_worker_url, _worker_schema_name | ||
|
|
||
|
|
||
| class TestWorkerSchemaName: | ||
| def test_valid_gw0(self): | ||
| """Return a schema name for the first xdist worker.""" | ||
| assert _worker_schema_name("gw0") == "test_worker_0" | ||
|
|
||
| def test_valid_gw99(self): | ||
| """Return a schema name for multi-digit xdist workers.""" | ||
| assert _worker_schema_name("gw99") == "test_worker_99" | ||
|
|
||
| def test_master_returns_none(self): | ||
| """Return ``None`` when pytest is not running under xdist.""" | ||
| assert _worker_schema_name("master") is None | ||
|
|
||
| def test_non_gw_id_returns_none(self): | ||
| """Ignore worker IDs that do not match the xdist pattern.""" | ||
| assert _worker_schema_name("worker1") is None | ||
|
|
||
| def test_partial_match_returns_none(self): | ||
| """Require a full worker ID match before creating a schema name.""" | ||
| # "gw0extra" should not match the fullmatch pattern | ||
| assert _worker_schema_name("gw0extra") is None | ||
|
|
||
|
|
||
| class TestBuildWorkerUrl: | ||
| def test_url_without_options(self): | ||
| """Add a search path option when the URL has no existing options.""" | ||
| url = "postgresql://user:pass@localhost/testdb" | ||
| result = _build_worker_url(url, "test_worker_0") | ||
| assert "options" in result | ||
| assert "search_path%3Dtest_worker_0" in result or "search_path=test_worker_0" in result | ||
|
|
||
| def test_url_with_existing_options_appends(self): | ||
| """Append the worker search path to existing connection options.""" | ||
| url = "postgresql://user:pass@localhost/testdb?options=-cstatement_timeout%3D5000" | ||
| result = _build_worker_url(url, "test_worker_1") | ||
| # The new search_path must be present | ||
| assert "search_path" in result | ||
| assert "test_worker_1" in result | ||
| # The original option must still be present | ||
| assert "statement_timeout" in result | ||
|
|
||
| def test_url_encoded_roundtrip(self): | ||
| """Preserve existing URL-encoded options while adding the worker search path.""" | ||
| url = "postgresql://user:pass@localhost/testdb?options=-cwork_mem%3D64MB" | ||
| result = _build_worker_url(url, "test_worker_2") | ||
| # Scheme, host, and path must be preserved | ||
| assert result.startswith("postgresql://user:pass@localhost/testdb") | ||
| assert "test_worker_2" in result | ||
| assert "work_mem" in result |
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.
Uh oh!
There was an error while loading. Please reload this page.