KAFKA-10861; Fix race condition in flaky test `testFencingOnSendOffsets` (#9762)

I wasn't able to reproduce the failure locally, but it looks like there is a race condition with the sending of the records in the first producer. The test case assumes that these records have been completed before the call to `sendOffsetsToTransaction`, but they very well might not be. It is even possible for the writes from the second producer to arrive first which would then result in the test failure that we are seeing. The solution is to force the send with `flush()`.

Reviewers: Guozhang Wang <guozhang@apache.org>, Boyang Chen <boyang@confluent.io>
This commit is contained in:
Jason Gustafson 2020-12-16 18:31:15 -08:00 committed by GitHub
parent f4272fd5d3
commit 4089c36b33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 0 deletions

View File

@ -356,6 +356,7 @@ class TransactionsTest extends KafkaServerTestHarness {
producer1.beginTransaction()
producer1.send(TestUtils.producerRecordWithExpectedTransactionStatus(topic1, null, "1", "1", willBeCommitted = false))
producer1.send(TestUtils.producerRecordWithExpectedTransactionStatus(topic2, null, "3", "3", willBeCommitted = false))
producer1.flush()
producer2.initTransactions() // ok, will abort the open transaction.
producer2.beginTransaction()