-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor opsqueue_service to use wait_for_server for port assignment and add utility function for server wait logic #34
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
base: reinier/log-bound-server-port
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |||
| import subprocess | ||||
| import uuid | ||||
| import os | ||||
| from libs.opsqueue_python.tests.util import wait_for_server | ||||
| import psutil | ||||
| import pytest | ||||
| from dataclasses import dataclass | ||||
| from pathlib import Path | ||||
|
|
@@ -52,13 +54,10 @@ def opsqueue() -> Generator[OpsqueueProcess, None, None]: | |||
|
|
||||
| @contextmanager | ||||
| def opsqueue_service( | ||||
| *, port: int | None = None | ||||
| *, port: int = 0, | ||||
| ) -> Generator[OpsqueueProcess, None, None]: | ||||
| global test_opsqueue_port_offset | ||||
|
||||
| global test_opsqueue_port_offset |
Copilot
AI
Dec 24, 2025
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.
The process type has been changed from subprocess.Popen to psutil.Popen, but the OpsqueueProcess dataclass still expects subprocess.Popen[bytes]. This type mismatch should be addressed by updating the dataclass type annotation to match. Note: psutil.Popen is a subclass of subprocess.Popen, so the code will work at runtime, but type checkers may report errors.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||||||||||||
| import logging | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import psutil | ||||||||||||||||||||
| from opnieuw import retry | ||||||||||||||||||||
| from psutil._common import pconn | ||||||||||||||||||||
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| LOGGER = logging.getLogger(__name__) | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| @retry( | ||||||||||||||||||||
| retry_on_exceptions=ValueError, | ||||||||||||||||||||
|
||||||||||||||||||||
| retry_on_exceptions=ValueError, | |
| retry_on_exceptions=(ValueError, RuntimeError), |
Copilot
AI
Dec 24, 2025
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.
The docstring states "If multiple ports are listening, a RuntimeError is thrown" but doesn't explain why this is considered an error condition. Since the function is designed to wait for servers that should listen on a single port, it would be helpful to document this assumption more clearly, such as: "This function expects the process to listen on exactly one port. If multiple ports are listening, a RuntimeError is raised as this indicates an unexpected server configuration."
| Wait for a process to be listening on a single port. | |
| If the process is listening on no ports, a ValueError is thrown and this is retried. | |
| If multiple ports are listening, a RuntimeError is thrown. | |
| Wait for a process to be listening on exactly one port and return that address. | |
| This function expects the given process to listen on a single port only. If the | |
| process is listening on no ports, a ValueError is raised and the check is retried. | |
| If multiple ports are listening, a RuntimeError is raised as this indicates an | |
| unexpected server configuration. |
Copilot
AI
Dec 24, 2025
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.
The new wait_for_server utility function lacks test coverage. Given that it contains complex logic with multiple error paths (process not running, access denied, zombie/dead status, no ports listening, multiple ports), this function should have dedicated unit tests to ensure reliability. The repository appears to use comprehensive testing (test files exist in the tests directory), so this new utility should follow the same pattern.
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.
The import statement uses an absolute path starting with
libs.opsqueue_python.tests.utilwhich might not work correctly depending on how the Python path is configured. Consider using a relative import likefrom .util import wait_for_serverorfrom tests.util import wait_for_serverinstead, which would be more robust to different project structures and import contexts.