Skip to content

Make AsyncWrapperTest deterministic (#40448) - #40449

Merged
Abacn merged 1 commit into
apache:masterfrom
tkaymak:fix-40448-asyncwrapper-test
Oct 8, 2026
Merged

Abacn merged 1 commit into
apache:masterfrom
tkaymak:fix-40448-asyncwrapper-test

Conversation

@tkaymak

@tkaymak tkaymak commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

testBufferStopsAcceptingItems asserted the buffer count after a fixed 100ms sleep and failed on loaded Windows runners with expected:<5> but was:<0>. The count is decremented in whenComplete as soon as a future finishes, so the assertion raced both the producer threads starting up and the buffered items completing. #38970 shortened the sleeps, which made the window smaller.

This change makes the test deterministic instead of widening the sleep:

  • BasicDofn takes an optional CountDownLatch gate, so a test can keep elements in flight until it releases them.
  • testBufferStopsAcceptingItems joins all 10 producers before asserting. With the gate closed nothing can complete, so exactly 5 items are buffered, 10 are in state and 0 are processed. After releasing the gate it checks that the first commit emits 5 and reschedules the 5 throttled items, and the second commit emits all 10. The scheduling timeout is shortened so throttled producers give up fast; the assertions do not depend on it.
  • testBufferCount, testBufferWithCancellation and testLongItem had the same sleep based race (10ms and 500ms DoFns) and now use the gate. testSlowDuplicates waits for the buffer to drain instead of sleeping.

Test only, no production change. Ran the class repeatedly on Linux, including with the build pinned to 2 cores under extra CPU load. The Windows failure itself does not reproduce locally, so the fix relies on the ordering above rather than on a repro.

Fixes #40448. This supersedes the timing based approach in #40397.


  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

testBufferStopsAcceptingItems asserted the buffer count after a fixed
100ms sleep, which failed on slow Windows runners (expected 5 but was 0).

Add an optional CountDownLatch gate to BasicDofn so tests hold elements
in-flight until they release it, instead of relying on wall-clock sleeps.
testBufferStopsAcceptingItems now joins all producers before asserting
that exactly 5 items are buffered, then verifies the 5 throttled items
are rescheduled and emitted. testBufferCount, testBufferWithCancellation
and testLongItem use the same gate; testSlowDuplicates waits for the
buffer to drain instead of sleeping.

Fixes apache#40448. Supersedes the timing-based approach in apache#40397.
@github-actions github-actions Bot added the java label Oct 7, 2026
@tkaymak tkaymak mentioned this pull request Oct 7, 2026
3 tasks
@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.74%. Comparing base (69bdf5f) to head (a9875e1).
⚠️ Report is 34 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #40449      +/-   ##
============================================
- Coverage     59.04%   58.74%   -0.31%     
+ Complexity    15624    13907    -1717     
============================================
  Files          2797     2584     -213     
  Lines        280750   271444    -9306     
  Branches      12488    11229    -1259     
============================================
- Hits         165764   159453    -6311     
+ Misses       108540   105995    -2545     
+ Partials       6446     5996     -450     
Flag Coverage Δ
java 65.24% <ø> (-0.21%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @chamikaramj for label java.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@derrickaw

Copy link
Copy Markdown
Collaborator

R: @Abacn since @chamikaramj is out for a few days

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@derrickaw

Copy link
Copy Markdown
Collaborator

Codecov/patch is stuck, but ready to review. Thanks

@Abacn Abacn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@Abacn
Abacn merged commit 69bfcac into apache:master Oct 8, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Failing Test]: AsyncWrapperTest.testBufferStopsAcceptingItems flaky on Windows

3 participants