[fix][test] Replace fixed sleeps with Awaitility polls in sink tests#86
Merged
david-streamlio merged 2 commits intoJul 10, 2026
Merged
Conversation
Five sink tests wrote to a sink that flushes asynchronously, waited a fixed Thread.sleep, then asserted the flush had happened. When CI is slow the flush has not run and the assertion fails: the sink is fine, the test raced it. This is the shape that failed unrelated PRs twice today, in InfluxDBSinkTest (v2) and PulsarSchemaHistoryTest. Poll the same conditions with Awaitility instead. The assertions are unchanged; only the waiting is. The tests also get faster, since a poll returns as soon as the condition holds. - mongo: MongoSinkTest, 5 sites - influxdb: InfluxDBGenericRecordSinkTest (v1) — sibling of the v2 test already deflaked - hdfs3: HdfsSequentialSinkTest, HdfsTextSinkTest — one asserted 5000 acks within a hard-coded 2 seconds - hbase: HbaseGenericRecordSinkTest — currently @test(enabled = false), so this is a compile-only change there
Contributor
There was a problem hiding this comment.
Pull request overview
This PR deflakes multiple sink unit tests by replacing fixed Thread.sleep(...) delays with Awaitility-based polling, ensuring assertions wait for asynchronous flush/ack behavior rather than racing it.
Changes:
- Replace fixed sleeps with
Awaitility.await().atMost(...).untilAsserted(...)in MongoDB, InfluxDB v1, and HDFS3 sink tests. - Update the HBase sink test (currently disabled) to poll for the row to appear instead of sleeping before reading it back.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| mongo/src/test/java/org/apache/pulsar/io/mongodb/MongoSinkTest.java | Replace multiple Thread.sleep(1000) calls with Awaitility polling for ack()/fail() verifications. |
| influxdb/src/test/java/org/apache/pulsar/io/influxdb/v1/InfluxDBGenericRecordSinkTest.java | Replace Thread.sleep(1000) with Awaitility polling for async batch flush verification. |
| hdfs3/src/test/java/org/apache/pulsar/io/hdfs3/sink/seq/HdfsTextSinkTest.java | Replace Thread.sleep(2000) with Awaitility polling for 100/5000 ack assertions. |
| hdfs3/src/test/java/org/apache/pulsar/io/hdfs3/sink/seq/HdfsSequentialSinkTest.java | Replace Thread.sleep(2000) with Awaitility polling for 100/5000 ack assertions. |
| hbase/src/test/java/org/apache/pulsar/io/hbase/sink/HbaseGenericRecordSinkTest.java | Replace Thread.sleep(500) with Awaitility polling until the written row is observable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
21
to
25
| import static org.mockito.Mockito.times; | ||
| import java.util.concurrent.TimeUnit; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.testng.Assert.assertNotNull; | ||
| import org.apache.pulsar.io.hdfs3.sink.AbstractHdfsSinkTest; |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Jul 10, 2026
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.
Fixes #85
Motivation
An audit for timing flakes found the same defect in four more modules. Each writes to a sink that flushes asynchronously, waits a fixed
Thread.sleep, then asserts the flush happened. On a slow runner the flush has not run and the assertion fails — the sink is fine, the test raced it.This shape has already failed two unrelated PRs today:
InfluxDBSinkTest.testOpenWriteCloseJson(v2) broke [fix][io] jdbc: drain flush() iteratively to avoid StackOverflowError under sustained backlog #39 → fixed in [improve][test] Add InfluxDB v1 and v2 sink integration tests, deflake the v2 mock test #73PulsarSchemaHistoryTest.setupbroke [fix][io] Fix DynamoDB source client construction with a custom endpoint #79 → fixed in [fix][test] Wait for the public tenant before creating the test namespace #84Findings
hdfs3HdfsSequentialSinkTest.write5000Testverify(..., times(5000)).ack()syncIntervalbackground synchdfs3HdfsSequentialSinkTest,HdfsTextSinkTestverify(..., times(100)).ack()mongoMongoSinkTest× 5 sitesverify(..., times(n)).ack()/.fail()flushExecutor.scheduleAtFixedRateinfluxdbv1InfluxDBGenericRecordSinkTestverify(influxDB, times(1)).write(...)BatchSinkflush executor — the very class whose v2 sibling flakedhbaseHbaseGenericRecordSinkTestHbaseAbstractSinkbatch flushwrite5000Testis the sharpest: 5000 acks asserted within a hard-coded 2 seconds.Modifications
Replace each fixed sleep with an Awaitility poll on the same condition. The assertions are unchanged — only the waiting is.
awaitilityis already on every module's test classpath via the shared java-conventions plugin. The tests also get faster, since a poll returns as soon as the condition holds rather than always sleeping the full duration.Verifying this change
All four suites pass:
./gradlew :mongo:test :influxdb:test :hdfs3:test :hbase:test→BUILD SUCCESSFUL.More importantly, the race is demonstrated, not asserted. Taking master's
MongoSinkTestand shortening its sleep from 1000 ms to 1 ms — simulating a runner slow enough that the flush has not fired — reproduces the CI signature exactly:The Awaitility version passes with no sleep at all, because it waits on the condition rather than on a guessed duration.
Notes
HbaseGenericRecordSinkTestis@Test(enabled = false)and does not run today, so its change is compile-only. Included so the pattern is not reintroduced when it is re-enabled.redis(sleeps but asserts nothing afterwards),jdbc/sqlite(sleep inside a retry loop),azure-data-explorer(credential-gated, never runs in CI — see [improve][test] Azure Data Explorer E2E test is always skipped in CI — add a runnable integration test #49), andfile(its sleeps are deliberate soak windows; its races were fixed in [fix][io] Fix duplicate file offers and flaky tests in file connector #41 and [fix][test] Bound record reads in Debezium MySQL and Postgres tests #71).