Skip to content

Conversation

@jan-janssen
Copy link
Member

@jan-janssen jan-janssen commented Sep 1, 2025

Summary by CodeRabbit

  • Tests
    • Added tests covering worker process termination during task execution and during initialization.
    • Ensures errors from terminated workers are consistently surfaced when retrieving results across different executor configurations.
    • Improves confidence in failure handling and robustness without altering user-facing behavior.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

Walkthrough

Adds tests in tests/test_singlenodeexecutor_noblock.py that introduce exit_funct() (calls sys.exit()) and a TestFunctionCrashes test class asserting that SingleNodeExecutor raises ExecutorlibSocketError when a worker process exits under several initialization scenarios.

Changes

Cohort / File(s) Summary of Changes
Tests: error-path coverage
tests/test_singlenodeexecutor_noblock.py
Added exit_funct() which calls sys.exit(). Introduced TestFunctionCrashes with three tests (test_single_node_executor, test_single_node_executor_block_allocation, test_single_node_executor_init_function) that submit or initialize with exit_funct and assert ExecutorlibSocketError on result retrieval. Minor import/format adjustments.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Tester
  participant SNE as SingleNodeExecutor
  participant Worker
  participant Future

  Tester->>SNE: submit(exit_funct)
  SNE->>Worker: start task
  Worker->>Worker: exit_funct() calls sys.exit()
  Worker--xSNE: connection closes (socket error)
  SNE->>Future: mark as failed with ExecutorlibSocketError
  Tester->>Future: result()
  Future-->>Tester: raise ExecutorlibSocketError
Loading
sequenceDiagram
  autonumber
  actor Tester
  participant SNE as SingleNodeExecutor(init_function=exit_funct)
  participant Worker
  participant Future

  Tester->>SNE: create executor
  SNE->>Worker: run init_function
  Worker->>Worker: exit_funct() calls sys.exit()
  Worker--xSNE: connection closes (socket error)
  SNE-->>Tester: subsequent submit/result raises ExecutorlibSocketError
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I’m a rabbit in the test suite den,
A function hopped and left again.
The socket sighed, the worker flew,
Tests now catch the sudden clue.
Hoppity hop — errors found, we grin! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch exit_tests

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Sep 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.75%. Comparing base (016a2ba) to head (29f6a5e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #802   +/-   ##
=======================================
  Coverage   97.75%   97.75%           
=======================================
  Files          32       32           
  Lines        1468     1468           
=======================================
  Hits         1435     1435           
  Misses         33       33           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/test_singlenodeexecutor_noblock.py (2)

26-29: Prefer a non-zero or abrupt exit to better simulate a crash

sys.exit() defaults to a clean exit (code 0). If you intend to simulate a crash/abrupt worker termination, exit with a non-zero code or use os._exit(1).

Apply one of these diffs:

-def exit_funct():
-    import sys
-    sys.exit()
+def exit_funct():
+    import sys
+    sys.exit(1)

or (stronger simulation of a hard crash):

-def exit_funct():
-    import sys
-    sys.exit()
+def exit_funct():
+    import os
+    os._exit(1)  # abrupt termination; skips atexit handlers

151-169: Flatten nested with statements and drop prints (SIM117); keep the focus on result() raising

  • Combine contexts per Ruff SIM117 for brevity.
  • print(f.result()) never executes (argument evaluation raises first) and adds noise.

Apply:

 class TestFunctionCrashes(unittest.TestCase):
     def test_single_node_executor(self):
-        with self.assertRaises(ExecutorlibSocketError):
-            with SingleNodeExecutor() as exe:
-                f = exe.submit(exit_funct)
-                print(f.result())
+        with self.assertRaises(ExecutorlibSocketError), SingleNodeExecutor() as exe:
+            exe.submit(exit_funct).result()

     def test_single_node_executor_block_allocation(self):
-        with self.assertRaises(ExecutorlibSocketError):
-            with SingleNodeExecutor(block_allocation=True) as exe:
-                f = exe.submit(exit_funct)
-                print(f.result())
+        with self.assertRaises(ExecutorlibSocketError), SingleNodeExecutor(block_allocation=True) as exe:
+            exe.submit(exit_funct).result()

     def test_single_node_executor_init_function(self):
-        with self.assertRaises(ExecutorlibSocketError):
-            with SingleNodeExecutor(init_function=exit_funct, block_allocation=True) as exe:
-                f = exe.submit(sum, [1, 1])
-                print(f.result())
+        with self.assertRaises(ExecutorlibSocketError), SingleNodeExecutor(init_function=exit_funct, block_allocation=True) as exe:
+            exe.submit(sum, [1, 1]).result()

(optional) If serialization ever flakes on some platforms, mirror other tests and call cloudpickle_register() before submit.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 016a2ba and 9314515.

📒 Files selected for processing (1)
  • tests/test_singlenodeexecutor_noblock.py (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/test_singlenodeexecutor_noblock.py (1)
executorlib/standalone/interactive/communication.py (1)
  • ExecutorlibSocketError (10-11)
🪛 Ruff (0.12.2)
tests/test_singlenodeexecutor_noblock.py

153-154: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)


159-160: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)


165-166: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: unittest_openmpi (ubuntu-22.04-arm, 3.13)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.13)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.12)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.11)
  • GitHub Check: unittest_win
  • GitHub Check: unittest_openmpi (ubuntu-24.04-arm, 3.13)
  • GitHub Check: unittest_openmpi (macos-latest, 3.13)
  • GitHub Check: unittest_mpich (macos-latest, 3.13)
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-mpich.yml)
  • GitHub Check: notebooks_integration
  • GitHub Check: unittest_flux_mpich
  • GitHub Check: unittest_flux_openmpi
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-openmpi.yml)
  • GitHub Check: unittest_slurm_mpich
🔇 Additional comments (2)
tests/test_singlenodeexecutor_noblock.py (2)

6-6: Good: asserting on the precise error type

Importing ExecutorlibSocketError enables clear, specific assertions in the new tests.


148-149: Confirm determinism of worker-id expectation under block_allocation=False

Asserting sum(...) == 0 assumes both tasks always run on worker 0. If scheduling can vary across platforms/backends, this may flake. Consider asserting “same worker” rather than the specific id.

If needed, use:

-        self.assertEqual(sum([f1_worker_id.result(), f2_worker_id.result()]), 0)
+        w1, w2 = f1_worker_id.result(), f2_worker_id.result()
+        self.assertEqual(w1, w2)      # both tasks handled by the same worker
+        self.assertIn(w1, (0, 1))     # allow backend-specific numbering

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
tests/test_singlenodeexecutor_noblock.py (5)

26-29: Make the simulated crash explicitly abnormal (non-zero exit).

Using sys.exit(1) better reflects a crash and avoids ambiguity with a clean exit status.

-def exit_funct():
-    import sys
-    sys.exit()
+def exit_funct():
+    import sys
+    sys.exit(1)

152-157: Remove print noise, add timeout, and merge context managers.

Prevents noisy test output, avoids hangs, and satisfies SIM117.

-        with self.assertRaises(ExecutorlibSocketError):
-            with SingleNodeExecutor(max_workers=2) as exe:
-                f = exe.submit(exit_funct)
-                print(f.result())
+        with self.assertRaises(ExecutorlibSocketError), SingleNodeExecutor(max_workers=2) as exe:
+            f = exe.submit(exit_funct)
+            _ = f.result(timeout=10)

159-163: Same cleanups for the block-allocation case.

-        with self.assertRaises(ExecutorlibSocketError):
-            with SingleNodeExecutor(max_workers=2, block_allocation=True) as exe:
-                f = exe.submit(exit_funct)
-                print(f.result())
+        with self.assertRaises(ExecutorlibSocketError), SingleNodeExecutor(max_workers=2, block_allocation=True) as exe:
+            f = exe.submit(exit_funct)
+            _ = f.result(timeout=10)

165-169: Apply the same pattern for the init_function path.

Keeps tests consistent, quieter, and less likely to hang.

-        with self.assertRaises(ExecutorlibSocketError):
-            with SingleNodeExecutor(max_workers=2, init_function=exit_funct, block_allocation=True) as exe:
-                f = exe.submit(sum, [1, 1])
-                print(f.result())
+        with self.assertRaises(ExecutorlibSocketError), SingleNodeExecutor(
+            max_workers=2, init_function=exit_funct, block_allocation=True
+        ) as exe:
+            f = exe.submit(sum, [1, 1])
+            _ = f.result(timeout=10)

151-169: De-duplicate the three crash tests.

Minor: factor a tiny helper to reduce repetition and speed future changes.

Example (outside these lines, for illustration):

def _expect_socket_error(self, **kwargs):
    with self.assertRaises(ExecutorlibSocketError), SingleNodeExecutor(**kwargs) as exe:
        f = exe.submit(exit_funct if 'init_function' not in kwargs else sum, [1,1]) if 'init_function' in kwargs else exe.submit(exit_funct)
        _ = f.result(timeout=10)

Then call it from each test with the respective kwargs.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9314515 and 29f6a5e.

📒 Files selected for processing (1)
  • tests/test_singlenodeexecutor_noblock.py (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/test_singlenodeexecutor_noblock.py (3)
executorlib/standalone/interactive/communication.py (1)
  • ExecutorlibSocketError (10-11)
executorlib/executor/single.py (1)
  • SingleNodeExecutor (20-189)
executorlib/task_scheduler/interactive/blockallocation.py (3)
  • max_workers (77-78)
  • max_workers (81-103)
  • submit (105-141)
🪛 Ruff (0.12.2)
tests/test_singlenodeexecutor_noblock.py

153-154: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)


159-160: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)


165-166: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: unittest_win
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-openmpi.yml)
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-mpich.yml)
  • GitHub Check: unittest_slurm_mpich
  • GitHub Check: unittest_flux_openmpi
  • GitHub Check: notebooks_integration
  • GitHub Check: unittest_mpich (macos-latest, 3.13)
  • GitHub Check: unittest_mpich (ubuntu-24.04-arm, 3.13)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.12)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.11)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.13)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.12)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.11)
  • GitHub Check: unittest_openmpi (ubuntu-22.04-arm, 3.13)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.13)
  • GitHub Check: unittest_openmpi (ubuntu-24.04-arm, 3.13)
  • GitHub Check: unittest_openmpi (macos-latest, 3.13)
  • GitHub Check: unittest_flux_mpich
🔇 Additional comments (2)
tests/test_singlenodeexecutor_noblock.py (2)

6-6: Import looks correct and scoped.

Bringing ExecutorlibSocketError from its defining module is appropriate for these tests.


148-149: Double-check determinism of expected worker-id sum.

Asserting a strict 0 may be brittle if scheduling varies by platform or CI load. Please confirm this is guaranteed by design for block_allocation=False, max_cores=2; otherwise consider a looser assertion (or document the invariant here).

@jan-janssen jan-janssen merged commit 1eaffea into main Sep 1, 2025
35 checks passed
@jan-janssen jan-janssen deleted the exit_tests branch September 1, 2025 05:51
@coderabbitai coderabbitai bot mentioned this pull request Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants