Skip to content

Refactor scheduled function execution to use explicit timing control#82

Draft
ianmacartney wants to merge 6 commits intomainfrom
ian/explicit-scheduler-queue
Draft

Refactor scheduled function execution to use explicit timing control#82
ianmacartney wants to merge 6 commits intomainfrom
ian/explicit-scheduler-queue

Conversation

@ianmacartney
Copy link
Copy Markdown
Member

@ianmacartney ianmacartney commented Mar 29, 2026

Refactor scheduled function execution to use explicit scheduling instead of setTimeout

This change replaces the setTimeout-based scheduled function execution with an explicit scheduling system that provides better control over test timing.

Key Changes:

  • Explicit execution control: Scheduled functions are no longer automatically executed via setTimeout. Instead, they are executed explicitly through finishInProgressScheduledFunctions() and finishAllScheduledFunctions()

  • Function path resolution: Added scheduledFunctionPaths map to track resolved function paths for function handles that may target different components than where the job is stored

  • Improved timer compatibility: Uses empty setTimeout calls as time markers that work with vi.advanceTimersByTime() and vi.runAllTimers() for precise test control

  • Sequential execution: Functions are now executed one at a time in order of scheduled time, with proper state management and error handling

  • Enhanced test utilities:

    • finishInProgressScheduledFunctions() now runs pending functions whose scheduled time has passed and waits for in-progress functions
    • finishAllScheduledFunctions() executes all pending functions in chronological order while advancing time as needed

This approach provides deterministic scheduled function execution in tests while maintaining compatibility with fake timer utilities.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a5bde50e-4f2c-478b-9209-3f0962892342

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ian/explicit-scheduler-queue

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 29, 2026

Open in StackBlitz

npm i https://pkg.pr.new/get-convex/convex-test@82

commit: 4864881

@ianmacartney ianmacartney changed the title Revert "allow setTimeout to work within actions (#78)" Refactor scheduled function execution to use explicit timing control Mar 29, 2026
@ianmacartney ianmacartney force-pushed the ian/explicit-scheduler-queue branch from 964b72d to 4864881 Compare April 1, 2026 20:57
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.

1 participant