-
Notifications
You must be signed in to change notification settings - Fork 95
Implement global PopenExecutor with tagging for improved process control and probe isolation #541
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
Draft
Copilot
wants to merge
6
commits into
main
Choose a base branch
from
copilot/fix-540
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.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eb604bc
Initial plan for issue
Copilot e0545e1
Implement global PopenExecutor with tagging support
Copilot f4bd62d
Final implementation with tests and linting fixes
Copilot 00b767f
Use function signature instead of name for tagging to ensure uniqueness
Copilot b421f6e
Address feedback: make tag required and simplify global executor init
Copilot d0262bc
Address feedback: simplify tagging API and remove unnecessary tests
Copilot 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
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,81 @@ | ||
| # SPDX-License-Identifier: AGPL-3.0 | ||
|
|
||
| from unittest.mock import Mock | ||
|
|
||
| from halmos.processes import PopenFuture, get_global_executor | ||
|
|
||
|
|
||
| def test_popen_future_with_tag(): | ||
| """Test that PopenFuture accepts and stores tag parameter.""" | ||
| cmd = ["echo", "hello"] | ||
| tag = "test-tag" | ||
|
|
||
| future = PopenFuture(cmd, tag) | ||
|
|
||
| assert future.cmd == cmd | ||
| assert future.tag == tag | ||
|
|
||
|
|
||
| def test_popen_future_with_minimal_args(): | ||
| """Test that PopenFuture works with minimal required parameters.""" | ||
| cmd = ["echo", "hello"] | ||
| tag = "test-minimal" | ||
|
|
||
| future = PopenFuture(cmd, tag) | ||
|
|
||
| assert future.cmd == cmd | ||
| assert future.tag == tag | ||
|
|
||
|
|
||
| def test_popen_future_empty_tag_assertion(): | ||
| """Test that PopenFuture raises assertion error for empty tag.""" | ||
| cmd = ["echo", "hello"] | ||
|
|
||
| try: | ||
| PopenFuture(cmd, "") | ||
| raise AssertionError("Expected AssertionError for empty tag") | ||
| except AssertionError: | ||
| pass # Expected | ||
|
|
||
|
|
||
| def test_interrupt_by_tag(): | ||
| """Test that interrupt() cancels futures with matching tags.""" | ||
| executor = get_global_executor() | ||
|
|
||
| # Create mock futures with different tags | ||
| future1 = Mock(spec=PopenFuture) | ||
| future1.tag = "tag1" | ||
| future2 = Mock(spec=PopenFuture) | ||
| future2.tag = "tag2" | ||
| future3 = Mock(spec=PopenFuture) | ||
| future3.tag = "tag1" | ||
| future4 = Mock(spec=PopenFuture) | ||
| future4.tag = "tag3" | ||
|
|
||
| # Add to executor's futures list | ||
| executor._futures = [future1, future2, future3, future4] | ||
|
|
||
| # Interrupt tag1 | ||
| executor.interrupt("tag1") | ||
|
|
||
| # Check that only futures with tag1 were cancelled | ||
| future1.cancel.assert_called_once() | ||
| future2.cancel.assert_not_called() | ||
| future3.cancel.assert_called_once() | ||
| future4.cancel.assert_not_called() | ||
|
|
||
|
|
||
| def test_interrupt_nonexistent_tag(): | ||
| """Test that interrupt() with non-existent tag does nothing.""" | ||
| executor = get_global_executor() | ||
|
|
||
| # Create mock future | ||
| future = Mock(spec=PopenFuture) | ||
| future.tag = "existing-tag" | ||
| executor._futures = [future] | ||
|
|
||
| # Interrupt with non-existent tag | ||
| executor.interrupt("nonexistent-tag") | ||
|
|
||
| # No futures should be cancelled | ||
| future.cancel.assert_not_called() |
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.
we probably want to assert that the tag is not empty
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.
Added assertion
assert tag, "tag cannot be empty"in PopenFuture constructor to validate non-empty tags. (b421f6e)