Skip to content

[Bug] Sink tests race their sinks' async flush: fixed Thread.sleep before verify() #85

Description

@david-streamlio

Summary

An audit for timing flakes turned up 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. When CI is slow, the flush has not run and the assertion fails — the sink is fine; the test raced it.

This is exactly the shape already fixed twice today:

Both took down PRs that never touched the code in question.

Findings

Module Test Sleep Then asserts Async mechanism
hdfs3 HdfsSequentialSinkTest.write5000Test 2000 ms verify(mockRecord, times(5000)).ack() syncInterval background sync
hdfs3 HdfsSequentialSinkTest (100 records), HdfsTextSinkTest 2000 ms verify(..., times(100)).ack() same
mongo MongoSinkTest × 3 (testWriteNullMessage, testWriteGoodMessage, testWriteMultipleMessages) 1000 ms verify(mockRecord, times(n)).ack()/.fail() flushExecutor.scheduleAtFixedRate(this::flush, ...)
influxdb (v1) InfluxDBGenericRecordSinkTest 1000 ms verify(influxDB, times(1)).write(...) BatchSink flush executor — the same class whose v2 sibling already flaked
hbase HbaseGenericRecordSinkTest 500 ms reads the row back from HBase HbaseAbstractSink batch flush

write5000Test is the sharpest: it asserts 5000 acks have landed within a hard-coded 2 seconds.

Lower priority / not flaky

Fix

Replace each fixed sleep with an Awaitility poll on the same condition (awaitility is already on every module's test classpath via the shared java-conventions plugin). The assertions stay identical; only the waiting changes. This removes the race without weakening any test — and speeds them up, since the poll returns as soon as the condition holds rather than always sleeping the full duration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions