test: add test that #3913 is fixed by #4026#4022
test: add test that #3913 is fixed by #4026#4022johanneskoester merged 3 commits intosnakemake:mainfrom
Conversation
📝 WalkthroughWalkthroughThis PR adds test coverage for GitHub issue Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/tests.py`:
- Around line 2939-2945: The test test_github_issue3913 fails on Windows because
its driven Snakefile uses Unix-only shell commands (touch/sleep); modify the
test to skip on Windows by adding the `@skip_on_windows` decorator (or equivalent
skip marker) to test_github_issue3913, or make the fixture portable by replacing
shell commands in the referenced Snakefile/run(...) invocation with
cross-platform Python-based operations (e.g., using python -c to create files
and sleep) so the test passes on Windows CI.
- Around line 2947-2974: The test currently can pass trivially because
active_job_thread_counts stays empty; modify the loop that reads the log (which
builds active_job_thread_counts using variables current_jobid and finished_jobid
and compares against core_count_limit) to track whether any job lifecycle lines
were actually observed (e.g., set a boolean saw_job_lifecycle when encountering
"jobid:", "threads", "resources:" or "Finished jobid:"), assert at the end of
the log processing that saw_job_lifecycle is true, and also assert that
active_job_thread_counts is empty after the loop finishes (ensuring all tracked
jobs were finished); keep the existing per-line thread-limit checks but only
rely on the trivial-pass path when appropriate and fail the test if no job lines
were parsed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bd610d05-385a-4b7f-9c8a-60a473120aed
📒 Files selected for processing (6)
src/snakemake/scheduling/job_scheduler.pytests/test_github_issue3913/Snakefiletests/test_github_issue3913/expected-results/commontests/test_github_issue3913/expected-results/file1tests/test_github_issue3913/expected-results/file2tests/tests.py
|
@edbennet, I just merged a PR by @fgvieira (#4026) that fixes the same issue. We decided that the advantage of not using the complex scheduler (LP) for just a single job is so marginal that it is not worth the additional code. However, your test case is still worth adding! Can you maybe resolve the conflict and then ping me via discord? |
c75b87b to
1f7d665
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/tests.py (1)
2998-3001: Don't tie this regression to the fixture's exact job count.The bug here is "never exceed the effective core budget", but Lines 2998-3000 also hard-code the current workflow shape. That makes the test fail on harmless fixture changes while the scheduler behavior is still correct. Prefer asserting that the parser observed lifecycle events, that starts and finishes match, and that no tracked jobs remain active at EOF.
Suggested change
- # Ensure that we observed every job we expect; - # avoid test passing spuriously if log format changes - assert completed_job_count == 4 and started_job_count == 4 + # Ensure the parser actually observed job lifecycle lines without + # coupling the regression to the fixture's current job graph. + assert started_job_count > 0 + assert completed_job_count > 0 + assert started_job_count == completed_job_count + assert not active_job_thread_counts shutil.rmtree(tmpdir, ignore_errors=ON_WINDOWS)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/tests.py` around lines 2998 - 3001, Replace the fragile exact-count assertion that checks completed_job_count == 4 and started_job_count == 4 with a check that ensures lifecycle consistency: assert started_job_count == completed_job_count and started_job_count > 0 (or >= 1) to confirm we observed starts and finishes, and also assert there are no active/tracked jobs at EOF (e.g., verify any active_jobs or outstanding_job set is empty). Keep the cleanup call shutil.rmtree(tmpdir, ignore_errors=ON_WINDOWS) intact; update references to completed_job_count and started_job_count accordingly (these variables are in the current test scope).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/tests.py`:
- Around line 2998-3001: Replace the fragile exact-count assertion that checks
completed_job_count == 4 and started_job_count == 4 with a check that ensures
lifecycle consistency: assert started_job_count == completed_job_count and
started_job_count > 0 (or >= 1) to confirm we observed starts and finishes, and
also assert there are no active/tracked jobs at EOF (e.g., verify any
active_jobs or outstanding_job set is empty). Keep the cleanup call
shutil.rmtree(tmpdir, ignore_errors=ON_WINDOWS) intact; update references to
completed_job_count and started_job_count accordingly (these variables are in
the current test scope).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b0dfb225-f34d-45a2-bc15-32565d567176
📒 Files selected for processing (5)
tests/test_github_issue3913/Snakefiletests/test_github_issue3913/expected-results/commontests/test_github_issue3913/expected-results/file1tests/test_github_issue3913/expected-results/file2tests/tests.py
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/test_github_issue3913/Snakefile
|
Thank you so much! |
Before this change, in some cases jobs were started without calling
update_available_resourcesto subtract the resources used from the resource pool. Regardless, when the job completed, the resources were re-added to the resource pool.This change ensures that the resource pool is always updated, and slightly rearranges the logic to avoid duplicating the call to
job_scheduler_greedy.The PR also includes a test that failed before the change, and now passes; it tests the behaviour described in the original issue (resources over allocated), rather than the specific bug fixed above.
fixes #3913
QC
docs/) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake).Summary by CodeRabbit