Fix Race with Delayed Idle

Defer setting the initial `lastReceive` until after the consumer is
created.

The `delayedIdleEvent()` test in `ConcurrentMessageListenerContainerMockTests`
could fail because the event might be published a few milliseconds before the
expected 500.
This commit is contained in:
Gary Russell
2023-07-17 14:00:52 -04:00
parent c7102f08de
commit dc6a38ffa0

View File

@@ -766,7 +766,7 @@ public class KafkaMessageListenerContainer<K, V> // NOSONAR line count
private boolean taskSchedulerExplicitlySet;
private long lastReceive = System.currentTimeMillis();
private long lastReceive;
private long lastAlertAt = this.lastReceive;
@@ -1299,6 +1299,7 @@ public class KafkaMessageListenerContainer<K, V> // NOSONAR line count
initAssignedPartitions();
publishConsumerStartedEvent();
Throwable exitThrowable = null;
this.lastReceive = System.currentTimeMillis();
while (isRunning()) {
try {
pollAndInvoke();