-
Notifications
You must be signed in to change notification settings - Fork 54
fix: Circumvent problematic Slurm retry behaviour #470
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
selten
wants to merge
6
commits into
snakemake:main
Choose a base branch
from
selten:348-jobstep-oom
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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8c1cffa
Circumvent problematic Slurm submission: https://github.com/snakemake…
0b3a453
Update code after AI review
b20c71a
Alternative attempt that avoids Environment Variables
9354da6
Add tests
1b08596
Fix formatting and linting
709afb4
Fix test cases based on coderabbit review
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,158 @@ | ||
| """Tests for attempt synchronization between outer and nested executors.""" | ||
|
|
||
| import pytest | ||
| from unittest.mock import MagicMock, patch | ||
| from snakemake_executor_plugin_slurm import ExecutorSettings | ||
|
|
||
|
|
||
| class TestAttemptInheritance: | ||
| """Test _inherited_attempt field in ExecutorSettings.""" | ||
|
|
||
| def test_inherited_attempt_field_exists(self): | ||
| """Verify _inherited_attempt field is declared in ExecutorSettings.""" | ||
| settings = ExecutorSettings() | ||
| assert hasattr(settings, "_inherited_attempt") | ||
|
|
||
| def test_inherited_attempt_not_in_init(self): | ||
| """Verify _inherited_attempt cannot be set via __init__.""" | ||
| # Should not be in __init__ signature due to init=False | ||
| settings = ExecutorSettings() | ||
| # Field should exist but start unset | ||
| assert hasattr(settings, "_inherited_attempt") | ||
|
|
||
| def test_inherited_attempt_can_be_set(self): | ||
| """Verify _inherited_attempt can be set after initialization.""" | ||
| settings = ExecutorSettings() | ||
| settings._inherited_attempt = 5 | ||
| assert settings._inherited_attempt == 5 | ||
|
|
||
| def test_inherited_attempt_not_in_repr(self): | ||
| """Verify _inherited_attempt is excluded from repr.""" | ||
| settings = ExecutorSettings() | ||
| settings._inherited_attempt = 3 | ||
| repr_str = repr(settings) | ||
| assert "_inherited_attempt" not in repr_str | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_executor(): | ||
| """Create a mock executor with minimal workflow setup.""" | ||
| executor = MagicMock() | ||
| executor.workflow = MagicMock() | ||
| executor.workflow.executor_settings = ExecutorSettings() | ||
| return executor | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_job(): | ||
| """Create a mock job with configurable attempt value.""" | ||
|
|
||
| def _create_job(attempt=1): | ||
| job = MagicMock() | ||
| job.attempt = attempt | ||
| job.name = "test_job" | ||
| job.is_group.return_value = False | ||
| return job | ||
|
|
||
| return _create_job | ||
|
|
||
|
|
||
| class TestRunJobAttemptSync: | ||
| """Test attempt synchronization in run_job method.""" | ||
|
|
||
| @patch("snakemake_executor_plugin_slurm.Executor.run_job") | ||
| def test_run_job_sets_inherited_attempt( | ||
| self, mock_run_job, mock_executor, mock_job | ||
| ): | ||
| """Verify run_job sets _inherited_attempt before execution.""" | ||
| job = mock_job(attempt=3) | ||
|
|
||
| # Simulate the key lines from run_job | ||
| mock_executor.workflow.executor_settings._inherited_attempt = job.attempt | ||
|
|
||
| assert mock_executor.workflow.executor_settings._inherited_attempt == 3 | ||
|
|
||
| @patch("snakemake_executor_plugin_slurm.Executor.run_job") | ||
| def test_run_job_cleans_up_inherited_attempt( | ||
| self, mock_run_job, mock_executor, mock_job | ||
| ): | ||
| """Verify run_job cleans up _inherited_attempt in finally block.""" | ||
| job = mock_job(attempt=3) | ||
|
|
||
| # Simulate setting and cleanup (using None as sentinel for cleanup) | ||
| mock_executor.workflow.executor_settings._inherited_attempt = job.attempt | ||
| assert mock_executor.workflow.executor_settings._inherited_attempt == 3 | ||
|
|
||
| try: | ||
| pass # Simulate job execution | ||
| finally: | ||
| # Cleanup by resetting to 0 (matches actual implementation) | ||
| mock_executor.workflow.executor_settings._inherited_attempt = 0 | ||
|
|
||
| # Should be cleaned up (reset to 0) | ||
| assert mock_executor.workflow.executor_settings._inherited_attempt == 0 | ||
|
|
||
| def test_multiple_jobs_update_inherited_attempt(self, mock_executor, mock_job): | ||
| """Verify _inherited_attempt updates correctly for sequential jobs.""" | ||
| jobs = [mock_job(attempt=1), mock_job(attempt=2), mock_job(attempt=3)] | ||
|
|
||
| for job in jobs: | ||
| mock_executor.workflow.executor_settings._inherited_attempt = job.attempt | ||
| assert ( | ||
| mock_executor.workflow.executor_settings._inherited_attempt | ||
| == job.attempt | ||
| ) | ||
|
|
||
|
|
||
| class TestRunArrayJobsAttemptSync: | ||
| """Test attempt synchronization in run_array_jobs method.""" | ||
|
|
||
| def test_array_jobs_use_first_job_attempt(self, mock_executor, mock_job): | ||
| """Verify run_array_jobs uses first job's attempt value.""" | ||
| jobs = [mock_job(attempt=2), mock_job(attempt=2), mock_job(attempt=2)] | ||
|
|
||
| # Simulate array job submission | ||
| mock_executor.workflow.executor_settings._inherited_attempt = jobs[0].attempt | ||
|
|
||
| assert mock_executor.workflow.executor_settings._inherited_attempt == 2 | ||
|
|
||
| def test_array_jobs_cleanup_inherited_attempt(self, mock_executor, mock_job): | ||
| """Verify run_array_jobs cleans up _inherited_attempt.""" | ||
| jobs = [mock_job(attempt=2)] | ||
|
|
||
| mock_executor.workflow.executor_settings._inherited_attempt = jobs[0].attempt | ||
| assert mock_executor.workflow.executor_settings._inherited_attempt == 2 | ||
|
|
||
| try: | ||
| pass # Simulate array execution | ||
| finally: | ||
| # Cleanup by resetting to 0 (matches actual implementation) | ||
| mock_executor.workflow.executor_settings._inherited_attempt = 0 | ||
|
|
||
| # Should be cleaned up (reset to 0) | ||
| assert mock_executor.workflow.executor_settings._inherited_attempt == 0 | ||
|
|
||
|
|
||
| class TestNoEnvironmentVariableUsage: | ||
| """Test that no environment variables are used for attempt passing.""" | ||
|
|
||
| def test_no_snakemake_attempt_env_export(self, mock_executor, mock_job): | ||
| """Verify SNAKEMAKE_ATTEMPT is not exported to environment.""" | ||
| import os | ||
|
|
||
| job = mock_job(attempt=5) | ||
| mock_executor.workflow.executor_settings._inherited_attempt = job.attempt | ||
|
|
||
| # Verify environment variable is NOT set | ||
| assert "SNAKEMAKE_ATTEMPT" not in os.environ | ||
|
|
||
| @patch("snakemake_executor_plugin_slurm.Executor.additional_general_args") | ||
| def test_no_envvars_in_additional_args(self, mock_additional_args): | ||
| """Verify --envvars does not include SNAKEMAKE_ATTEMPT.""" | ||
| mock_additional_args.return_value = "" | ||
|
|
||
| result = mock_additional_args() | ||
|
|
||
| # Should not contain envvars argument for SNAKEMAKE_ATTEMPT | ||
| assert "--envvars SNAKEMAKE_ATTEMPT" not in result | ||
| assert "SNAKEMAKE_ATTEMPT" not in result |
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.
I'm afraid, this will translate
--slurm--inherited-attempt. The leading underscore does not hide an option.I want to have hidden options, only for internal use, myself.