Skip to content

test(amber): add unit test coverage for FlowControl#4750

Merged
Yicong-Huang merged 5 commits into
apache:mainfrom
aglinxinyuan:xinyuan-test-flow-control-spec
May 3, 2026
Merged

test(amber): add unit test coverage for FlowControl#4750
Yicong-Huang merged 5 commits into
apache:mainfrom
aglinxinyuan:xinyuan-test-flow-control-spec

Conversation

@aglinxinyuan
Copy link
Copy Markdown
Contributor

@aglinxinyuan aglinxinyuan commented May 3, 2026

What changes were proposed in this PR?

Add FlowControlSpec covering the credit-based backpressure manager in FlowControl:

  • Initial state: full credit, not overloaded
  • getMessagesToSend(msg) forwards when credit available; stashes and marks overloaded when credit is exhausted
  • Stashed messages drain once credit is restored
  • New messages arriving while the stash is non-empty are stashed first and drained in FIFO order behind older work
  • Partial drain: when restored credit only fits a subset of the stash, isOverloaded remains true while the rest waits
  • updateQueuedCredit shrinks available credit and is relative (not cumulative)
  • decreaseInflightCredit frees credit equal to the acked amount (seeded via a real getMessagesToSend rather 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)

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-commenter
Copy link
Copy Markdown

codecov-commenter commented May 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.41%. Comparing base (c7457f7) to head (3165897).

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     
Flag Coverage Δ
amber 41.68% <ø> (+0.03%) ⬆️
python 85.34% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 FlowControlSpec validating 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) and decreaseInflightCredit effects on available credit.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

aglinxinyuan and others added 2 commits May 2, 2026 19:03
- 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>
@aglinxinyuan
Copy link
Copy Markdown
Contributor Author

@copilot please re-review — addressed audit gaps in latest commit.

@Yicong-Huang Yicong-Huang enabled auto-merge (squash) May 3, 2026 07:35
aglinxinyuan and others added 2 commits May 3, 2026 01:27
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>
@Yicong-Huang Yicong-Huang merged commit f4c352d into apache:main May 3, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add unit test coverage for FlowControl

4 participants