Skip to content

PYTHON-5784 Coverage increase for periodic_executor.py#2771

Merged
aclark4life merged 14 commits into
mongodb:masterfrom
aclark4life:PYTHON-5784
Jun 4, 2026
Merged

PYTHON-5784 Coverage increase for periodic_executor.py#2771
aclark4life merged 14 commits into
mongodb:masterfrom
aclark4life:PYTHON-5784

Conversation

@aclark4life

@aclark4life aclark4life commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

PYTHON-5784

Changes in this PR

Adds test/asynchronous/test_periodic_executor.py (synchro'd to test/test_periodic_executor.py) with unit tests for pymongo/periodic_executor.py, covering both PeriodicExecutor and AsyncPeriodicExecutor:

  • join() before open() is a safe no-op.
  • Target returning False stops the executor.
  • Target raising an exception stops the executor (verified by asserting target is called exactly once).
  • skip_sleep() causes the next iteration to run without waiting the full interval.
  • wake() interrupts the current sleep and triggers an early run.
  • open() after the target returned False restarts the executor.

Test Plan

Added unit tests using asyncio.Event / threading.Event for deterministic synchronization. The exception test swaps threading.excepthook to a no-op so the intentional RuntimeError in the worker thread is not surfaced by pytest's threadexception plugin (no-op for the async executor since no thread is involved).

uv run --extra test python -m pytest test/asynchronous/test_periodic_executor.py test/test_periodic_executor.py -v

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

Loading
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.

5 participants