test: validate sleep() works correctly inside loops#1415
test: validate sleep() works correctly inside loops#1415
Conversation
Validates a user-reported concern that sleep() inside a loop with step calls fires all iterations instantly. The test confirms sleep is honored on replay — 3 iterations with 3s sleeps take ~6s+ total elapsed time. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 0070fa2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🧪 E2E Test Results❌ Some tests failed Summary
❌ Failed Tests🐘 Local Postgres (2 failed)express-stable (1 failed):
nextjs-turbopack-canary (1 failed):
🌍 Community Worlds (56 failed)mongodb (3 failed):
redis (2 failed):
turso (51 failed):
Details by Category✅ ▲ Vercel Production
✅ 💻 Local Development
✅ 📦 Local Production
❌ 🐘 Local Postgres
✅ 🪟 Windows
❌ 🌍 Community Worlds
✅ 📋 Other
❌ Some E2E test jobs failed:
Check the workflow run for details. |
📊 Benchmark Results
workflow with no steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express | Nitro | Next.js (Turbopack) workflow with 1 step💻 Local Development
▲ Production (Vercel)
🔍 Observability: Next.js (Turbopack) | Nitro | Express workflow with 10 sequential steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express | Nitro | Next.js (Turbopack) workflow with 25 sequential steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Nitro | Next.js (Turbopack) | Express workflow with 50 sequential steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express | Next.js (Turbopack) | Nitro Promise.all with 10 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express | Next.js (Turbopack) | Nitro Promise.all with 25 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express | Next.js (Turbopack) | Nitro Promise.all with 50 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Next.js (Turbopack) | Express | Nitro Promise.race with 10 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Next.js (Turbopack) | Nitro | Express Promise.race with 25 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Nitro | Express | Next.js (Turbopack) Promise.race with 50 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Nitro | Express | Next.js (Turbopack) Stream Benchmarks (includes TTFB metrics)workflow with stream💻 Local Development
▲ Production (Vercel)
🔍 Observability: Nitro | Express | Next.js (Turbopack) SummaryFastest Framework by WorldWinner determined by most benchmark wins
Fastest World by FrameworkWinner determined by most benchmark wins
Column Definitions
Worlds:
|
There was a problem hiding this comment.
Pull request overview
Adds an end-to-end regression test to ensure sleep() calls inside a loop (interleaved with step calls) introduce real delays between iterations, addressing a reported “instant replay” concern.
Changes:
- Add
sleepInLoopWorkflowand a supporting step (noopStep) to the example e2e workflows. - Add a new core e2e test asserting the workflow shows elapsed time consistent with loop sleeps.
- Add a changeset bumping
@workflow/core(patch) for the added e2e coverage.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| workbench/example/workflows/99_e2e.ts | Adds a new workflow + step that records timestamps across loop iterations separated by sleep() calls. |
| packages/core/e2e/e2e.test.ts | Adds an e2e test that runs the new workflow and asserts the elapsed time indicates sleeps occurred. |
| .changeset/add-sleep-in-loop-e2e-test.md | Publishes a patch changeset for @workflow/core tied to the new e2e test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| export async function sleepInLoopWorkflow() { | ||
| 'use workflow'; | ||
| const iterations = 3; | ||
| const sleepMs = 3_000; // 3s per iteration |
There was a problem hiding this comment.
Fixed — changed to "3s between iterations (2 sleeps total)".
packages/core/e2e/e2e.test.ts
Outdated
| const run = await start(await e2e('sleepInLoopWorkflow'), []); | ||
| const returnValue = await run.returnValue; | ||
|
|
||
| // 3 iterations with 3s sleep between each pair = ~6s minimum total elapsed |
There was a problem hiding this comment.
Updated the comment to say "2.5s threshold per sleep to allow jitter" which matches the actual assertion.
| const returnValue = await run.returnValue; | ||
|
|
||
| // 3 iterations with 3s sleep between each pair = ~6s minimum total elapsed | ||
| expect(returnValue.timestamps).toHaveLength(3); |
There was a problem hiding this comment.
Good call — added per-iteration delta assertions (delta1 > 2500 and delta2 > 2500) so each individual sleep is validated.
- Fix misleading "3s per iteration" comment to "3s between iterations" - Update test comment to reflect 2.5s jitter-tolerant threshold - Add per-iteration delta assertions to ensure each individual sleep fires Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
sleepInLoopWorkflow) that validatessleep()inside a loop with step calls correctly delays each iterationsleep()in a loop fires all iterations instantly on replay — this test proves that's not the caseTest plan
sleepInLoopWorkflowe2e test against local world (nextjs-turbopack dev server) — passed in ~8s🤖 Generated with Claude Code