Skip to content

Commit a6e35f9

Browse files
committed
Txn integration tests: rely on KIP-447
1 parent 00156ec commit a6e35f9

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

kafka/txn_integration_test.go

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -297,34 +297,27 @@ func TestTransactionalSendOffsets(t *testing.T) {
297297
}
298298
}
299299

300+
// Create consumer (to read committed offsets) prior to closing the
301+
// consumer to trigger the race condition where the transaction is
302+
// not fully committed by the time consumer.Committed() is called.
303+
// Prior to KIP-447 this would result in the committed offsets not
304+
// showing up, but with KIP-447 the consumer automatically retries
305+
// the offset retrieval.
306+
t.Logf("Creating consumer for (later) offset retrieval\n")
307+
consumer, err := NewConsumer(consumerConfig)
308+
if err != nil {
309+
t.Fatalf("Failed to create Consumer client: %s\n", err)
310+
}
311+
312+
// Close producer
300313
// signal go-routine to finish
301314
close(termChan)
302315
// wait for go-routine to finish
303316
_ = <-doneChan
304317

305318
producer.Close()
306319

307-
// Until KIP-447 is implemented we need to call
308-
// InitTransactions() after transactions are committed to make
309-
// sure the committed offsets are made available to consumers.
310-
producer2, err := NewProducer(config)
311-
if err != nil {
312-
t.Fatalf("Failed to create Producer client: %s\n", err)
313-
}
314-
315-
err = producer2.InitTransactions(nil)
316-
if err != nil {
317-
t.Fatalf("InitTransactions() failed: %v\n", err)
318-
}
319-
320-
producer2.Close()
321-
322-
// Read committed offsets.
323-
consumer, err := NewConsumer(consumerConfig)
324-
if err != nil {
325-
t.Fatalf("Failed to create Consumer client: %s\n", err)
326-
}
327-
320+
t.Logf("Retrieving committed offsets\n")
328321
committed, err := consumer.Committed(partitions, -1)
329322
if err != nil {
330323
t.Fatalf("Failed to get committed offsets: %s\n", err)

0 commit comments

Comments
 (0)