fix(batch): detect item timeout by elapsed time, not context state#123
Conversation
Re-enable the previously commented-out TestBatch_ErrorIdentification, including the BatchTimeout and ItemTimeout subtests. Adds the withTestGlobal(t) setup used by every other test in this file so the batch runs against an isolated test manager.
The post-execution item-timeout verdict checked itemCtx.Err() == context.DeadlineExceeded. Because item callables do not receive the context, an over-budget item always runs to completion and the timeout was only guessed afterwards from context state. When the parent batchCtx was cancelled by the batch timeout before the item's own deadline expired, itemCtx.Err() returned context.Canceled instead of context.DeadlineExceeded, so an overrun item was wrongly reported as a successful result. With Timeout left at zero, Run() defaults it to len(items)*ItemTimeout, which for a single 50ms item equals the item timeout, so two 50ms timers raced and the outcome flipped per run (TestBatch_ErrorIdentification/ItemTimeout was ~80% failing). Base the verdict on deterministic wall-clock time: duration > ItemTimeout. This only flags items that exceeded their own per-item budget regardless of which timer fired, and leaves batch-level cancellation to the monitoring goroutine. The test now passes 30/30 and under -race.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughIn ChangesDeterministic item timeout detection and error identification tests
🚥 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 docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
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 |
Gavel summary
Totals: 1996 passed · 0 failed · 63 skipped · 1m53s |
|
🎉 This PR is included in version 1.21.25 |
Closes #61.
The post-execution item-timeout verdict in
Batch.RuncheckeditemCtx.Err() == context.DeadlineExceeded. Because item callables do not receive the context, an over-budget item always runs to completion and the timeout was only inferred afterwards from context state. When the parentbatchCtxwas cancelled by the batch timeout before the item's own deadline expired,itemCtx.Err()returnedcontext.Canceledinstead ofcontext.DeadlineExceeded, so an overrun item was wrongly reported as a successful result.With
Timeoutleft at zero,Rundefaults it tolen(items)*ItemTimeout, which for a single 50ms item equals the item timeout — so two 50ms timers raced and the outcome flipped per run.Base the verdict on deterministic wall-clock time:
duration > ItemTimeout. This only flags items that exceeded their own per-item budget regardless of which timer fired, and leaves batch-level cancellation to the monitoring goroutine.Split into two commits: the first re-enables
TestBatch_ErrorIdentification(was commented out), the second applies the production fix.Summary by CodeRabbit
Bug Fixes
Tests