-
Notifications
You must be signed in to change notification settings - Fork 261
🧪 test_calc_job: fix daemon-restart flake
#7452
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
GeigerJ2
wants to merge
2
commits into
aiidateam:main
Choose a base branch
from
GeigerJ2:fix/7152/restart-daemon-test-polling
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.
+49
−36
Open
Changes from all commits
Commits
Show all changes
2 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
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 |
|---|---|---|
|
|
@@ -113,17 +113,18 @@ def test(submit_and_await): | |
| :param submittable: A process, a process builder or a process node. If it is a process or builder, it is submitted | ||
| first before awaiting the desired state. | ||
| :param state: The process state to wait for, by default it waits for the submittable to be ``FINISHED``. | ||
| :param timeout: The time to wait for the process to achieve the state. | ||
| :param timeout: The number of seconds to wait for the process to achieve the state. | ||
| :param kwargs: If the ``submittable`` is a process class, it is instantiated with the ``kwargs`` as inputs. | ||
| :raises RuntimeError: If the process fails to achieve the specified state before the timeout expires. | ||
| :raises RuntimeError: If the process terminates in a state other than the one specified, or if it fails to | ||
| achieve the specified state before the timeout expires. | ||
| :returns `~aiida.orm.nodes.process.process.ProcessNode`: The process node. | ||
| """ | ||
| from aiida.engine import ProcessState | ||
|
|
||
| def factory( | ||
| submittable: type[Process] | ProcessBuilder | ProcessNode, | ||
| state: ProcessState = ProcessState.FINISHED, | ||
| timeout: int = 20, | ||
| timeout: float = 20, | ||
| **kwargs, | ||
| ): | ||
| import inspect | ||
|
|
@@ -141,22 +142,33 @@ def factory( | |
| else: | ||
| raise ValueError(f'type of submittable `{type(submittable)}` is not supported.') | ||
|
|
||
| start_time = time.time() | ||
| start_time = time.monotonic() | ||
| # Terminal members of ``ProcessState``, mirroring ``ProcessNode.is_terminated``. | ||
| terminal_states = (ProcessState.EXCEPTED, ProcessState.FINISHED, ProcessState.KILLED) | ||
|
|
||
| while node.process_state is not state: | ||
| if node.is_excepted: | ||
| raise RuntimeError(f'The process excepted: {node.exception}') | ||
| while True: | ||
| # Read ``process_state`` once per iteration: each access re-queries the database, so splitting the target | ||
| # and terminal checks across reads could straddle a transition and fail just as ``state`` is reached. | ||
| current_state = node.process_state | ||
|
|
||
| if time.time() - start_time >= timeout: | ||
| if current_state is state: | ||
| return node | ||
|
|
||
| # A terminal state cannot change, so waiting for a different one would only delay the failure. | ||
| if current_state in terminal_states: | ||
| if current_state is ProcessState.EXCEPTED: | ||
| raise RuntimeError(f'The process excepted: {node.exception}') | ||
| msg = f'The process terminated in state `{current_state}` while waiting for state `{state}`.' | ||
| raise RuntimeError(msg) | ||
|
Comment on lines
+159
to
+162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Assign the exception message before raising in both fixtures.
As per coding guidelines, assign exception messages to a variable before raising. 📍 Affects 2 files
🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| if time.monotonic() - start_time >= timeout: | ||
| daemon_log_file = pathlib.Path(started_daemon_client.daemon_log_file).read_text(encoding='utf-8') | ||
| daemon_status = 'running' if started_daemon_client.is_daemon_running else 'stopped' | ||
| raise RuntimeError( | ||
| f'Timed out waiting for process with state `{node.process_state}` to enter state `{state}`.\n' | ||
| f'Timed out waiting for process with state `{current_state}` to enter state `{state}`.\n' | ||
| f'Daemon <{started_daemon_client.profile.name}|{daemon_status}> log file content: \n' | ||
| f'{daemon_log_file}' | ||
| ) | ||
| time.sleep(0.1) | ||
|
|
||
| return node | ||
|
|
||
| return factory | ||
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use
:return:consistently in both factory docstrings.src/aiida/tools/pytest_fixtures/daemon.py#L120-L120: replace:returns:with:return:.src/aiida/manage/tests/pytest_fixtures.py#L733-L741: add the factory’s:return:field.As per coding guidelines, use Sphinx-style docstrings with
:param:,:return:, and:raises:.📍 Affects 2 files
src/aiida/tools/pytest_fixtures/daemon.py#L120-L120(this comment)src/aiida/manage/tests/pytest_fixtures.py#L733-L741🤖 Prompt for AI Agents
Source: Coding guidelines