Skip to content

Conversation

@majialoong
Copy link
Contributor

@majialoong majialoong commented Dec 2, 2025

The test testMonitorableSinkConnectorAndTask is flaky due to a race
condition between the task thread and the test thread.

The awaitRecords() method uses a CountDownLatch that counts down in
TestableSinkTask.put() for each record inside the loop, while
MonitorableSinkTask.count is updated after super.put() returns. When
the latch reaches zero, awaitRecords() returns immediately, but the
count += records.size() may not have executed yet.

@github-actions github-actions bot added triage PRs from the community connect tests Test fixes (including flaky tests) small Small PRs labels Dec 2, 2025
@majialoong
Copy link
Contributor Author

I added logging to verify the race condition.

In MonitorableSinkTask.put():

@Override
public void put(Collection<SinkRecord> records) {
    super.put(records);
    count += records.size();
    // add log
    System.out.println("MonitorableSinkTask: count updated to: " + count);
}

In MonitorableSinkIntegrationTest (before fix):

// add log
log.info("Task metric value: {}", metrics.get(taskMetric).metricValue());
assertEquals((double) NUM_RECORDS_PRODUCED, metrics.get(taskMetric).metricValue());

Successful run:
image

Failed run:
image

The logs clearly show the race condition:

  1. In the failed run, awaitRecords() returns (latch countdown completed) before the last count += records.size() executes.
  2. The test thread reads the metric value 999.0 while the task thread has not yet updated count to 1000.
  3. The count updated to: 1000 log appears after the test reads the metric, confirming the race.

@mimaison mimaison added ci-approved and removed triage PRs from the community labels Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-approved connect small Small PRs tests Test fixes (including flaky tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants