Skip to content

[fix][test] Fix flaky PulsarFunctionsJavaThreadTest.testTumblingCountWindowTest#25590

Merged
lhotari merged 5 commits intoapache:masterfrom
cognitree:fix/tumbling-count-window
Apr 28, 2026
Merged

[fix][test] Fix flaky PulsarFunctionsJavaThreadTest.testTumblingCountWindowTest#25590
lhotari merged 5 commits intoapache:masterfrom
cognitree:fix/tumbling-count-window

Conversation

@Praveenkumar76
Copy link
Copy Markdown
Contributor

Fixes apache#25391

Motivation

PulsarFunctionsJavaThreadTest.testTumblingCountWindowTest fails intermittently in CI with assertion errors such as:

expected [1] but found [3]

The failure is caused by race conditions in the test. It validates TopicStats and SubscriptionStats immediately after producing messages, while broker statistics are updated asynchronously. As a result, the test may read stale or partially updated values.

Additionally, some assertions use inverted parameter ordering, which makes failure messages harder to interpret.

Modifications

  • Replaced immediate metric assertions with Awaitility.await().untilAsserted(...) so the test waits until broker stats reach the expected values.
  • Applied asynchronous waiting for both backlog verification and final acknowledgment / cleanup checks.
  • Corrected assertEquals argument ordering to improve assertion readability and failure diagnostics.
  • Improved test stability by aligning assertions with the eventual consistency behavior of broker metrics.

Verifying this change

This change is a bug fix and was verified manually:

  • Re-ran PulsarFunctionsJavaThreadTest.testTumblingCountWindowTest multiple times locally without intermittent failures.
  • Confirmed the test now waits for expected metrics before asserting.
  • Executed the targeted Gradle integration test successfully:
./gradlew :tests:integration:test --tests "*PulsarFunctionsJavaThreadTest.testTumblingCountWindowTest"

Starting a Gradle Daemon (subsequent builds will be faster)
Configuration on demand is an incubating feature.
Reusing configuration cache.

BUILD SUCCESSFUL in 2s
98 actionable tasks: 5 executed, 1 from cache, 92 up-to-date
  • CI validation pending / to be confirmed after PR run.

Does this pull request potentially affect one of the following parts:

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Copy link
Copy Markdown
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

minor details in using Awaitility

@Praveenkumar76 Praveenkumar76 requested a review from lhotari April 28, 2026 07:38
@Praveenkumar76
Copy link
Copy Markdown
Contributor Author

@lhotari ! I've removed the redundant Awaitility defaults as suggested and ensured the CI checks are passing

Copy link
Copy Markdown
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the contribution @Praveenkumar76

@lhotari lhotari merged commit b56c1de into apache:master Apr 28, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky-test: PulsarFunctionsJavaThreadTest.testTumblingCountWindowTest

2 participants