async def _test_control_record(self, isolation_level): producer = AIOKafkaProducer( loop=self.loop, bootstrap_servers=self.hosts, transactional_id="sobaka_producer") await producer.start() self.add_cleanup(producer.stop) async with producer.transaction(): meta = await producer.send_and_wait( self.topic, b'Hello from transaction', partition=0) consumer = AIOKafkaConsumer( self.topic, loop=self.loop, bootstrap_servers=self.hosts, auto_offset_reset="earliest", isolation_level=isolation_level, fetch_max_bytes=10) await consumer.start() self.add_cleanup(consumer.stop) # Transaction marker will be next after the message consumer.seek(meta.topic_partition, meta.offset + 1) with self.assertRaises(asyncio.TimeoutError): await asyncio.wait_for( consumer.getone(), timeout=0.5, loop=self.loop) # We must not be stuck on previous position position = await consumer.position(meta.topic_partition) self.assertEqual(position, meta.offset + 2) # After producing some more data it should resume consumption async with producer.transaction(): meta2 = await producer.send_and_wait( self.topic, b'Hello from transaction 2', partition=0) msg = await consumer.getone() self.assertEqual(msg.offset, meta2.offset) self.assertEqual(msg.timestamp, meta2.timestamp) self.assertEqual(msg.value, b"Hello from transaction 2") self.assertEqual(msg.key, None)