test(amber): add unit test coverage for FlowControl#4750
Merged
Yicong-Huang merged 5 commits intoMay 3, 2026
Conversation
Add `FlowControlSpec` covering the credit-based backpressure manager: initial credit, forward/stash on `getMessagesToSend`, drain after credit restoration, `updateQueuedCredit` shrinking and overwrite semantics, and `decreaseInflightCredit` accounting. Closes apache#4749 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4750 +/- ##
============================================
+ Coverage 43.39% 43.41% +0.01%
Complexity 2048 2048
============================================
Files 957 957
Lines 34077 34077
Branches 3753 3753
============================================
+ Hits 14789 14795 +6
+ Misses 18495 18491 -4
+ Partials 793 791 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds ScalaTest unit coverage for Amber’s FlowControl credit-based backpressure logic to prevent regressions in credit accounting and stashing/draining behavior (closes #4749).
Changes:
- Introduces
FlowControlSpecvalidating initial credit state and overload flag behavior. - Adds tests for message forwarding vs. stashing when credit is exhausted, and draining after credit restoration.
- Adds tests for
updateQueuedCredit(relative semantics) anddecreaseInflightCrediteffects on available credit.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Replace the unused `fixedMsgSize` literal with a `msgSize` derived from `WorkflowMessage.getInMemSize`, asserted to be 200L. This pins the assumption rather than carrying a dead constant. - Rework the `decreaseInflightCredit` test to seed inflight via `getMessagesToSend` and acknowledge by the actual message size, instead of passing a negative amount which would not match the real caller contract. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…Send Audit gap: the existing drain test only exercised the no-arg `getMessagesToSend` after a single stashed message. The branch where a NEW message arrives while the stash is already non-empty was not covered. Add two cases: - A new message arriving with available credit is still stashed first and then drained in FIFO order behind the older one. - When only enough credit is restored for a subset of the stash, `isOverloaded` must remain true while the rest waits. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@copilot please re-review — addressed audit gaps in latest commit. |
Yicong-Huang
approved these changes
May 3, 2026
Per Yicong-Huang's review on apache#4750: extend coverage of the "algorithm and edge cases": - 1000-sequential-message run inside size-cap (the strict over-cap assertion is unreachable in unit-test scope without synthesizing multi-GB payloads, but the guard shape is still pinned by passing many 200L payloads through) - Multi-run drain: stash 20 messages, then alternately restore one-message-worth of credit and drain — verifies all messages eventually drain - updateQueuedCredit: accepts zero (reset) and negative input (overshoot — pinned so a future validator surfaces as a regression) - decreaseInflightCredit: tolerated no-op for amount = 0 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this PR?
Add
FlowControlSpeccovering the credit-based backpressure manager inFlowControl:getMessagesToSend(msg)forwards when credit available; stashes and marks overloaded when credit is exhaustedisOverloadedremains true while the rest waitsupdateQueuedCreditshrinks available credit and is relative (not cumulative)decreaseInflightCreditfrees credit equal to the acked amount (seeded via a realgetMessagesToSendrather than a synthetic negative input, so the test mirrors actual caller usage)Any related issues, documentation, discussions?
Closes #4749
How was this PR tested?
sbt "WorkflowExecutionService/testOnly org.apache.texera.amber.engine.architecture.messaginglayer.FlowControlSpec"— 9/9 tests pass.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.7)