'Integration test does not wait for Kafka consumer client to retrieve all the events
I have an integration test which calls the original service A. This service A only produces events for other services in the Kafka broker with topic: "X" and consumer group: "Y". One of the objective of my integration test is just to verify the events published by the service A. For this, I created another consumer group: "Y-test" and the same topic: "X". Integration test wont be producing any events but it just tries to consume the events created by Service A in topic:"X". The issue i am facing is my integration test is erratic. Sometimes it waits for the kafka streamListener in integration test for all the events in the broker or sometimes it does not wait to consume the events, instead goes with next steps, kind of like skipping the steps for messages/events to be consumed. The expiry period for the events are around 7 days and i also verified in the kafka, if the produced events are still there and its still there.
Is there a way for me to make my tests wait until all the events are consumed by my streamlistener in integration test before proceeding with rest of steps. The only way i think is by creating some kind of ListenableFuture or something similar using threads, but i am not sure if there are any simpler way to do it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
