Skip to content

Commit

Permalink
Fix Race in DMLC Events test
Browse files Browse the repository at this point in the history
ConsumeOkEvent introduced a race condition into the test.
  • Loading branch information
garyrussell committed Dec 26, 2017
1 parent 822593b commit 802a741
Showing 1 changed file with 1 addition and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.springframework.amqp.rabbit.listener;

import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -68,7 +67,6 @@
import org.springframework.amqp.support.converter.MessageConversionException;
import org.springframework.amqp.utils.test.TestUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
Expand Down Expand Up @@ -317,15 +315,13 @@ public void testEvents() throws Exception {
container.setQueueNames(EQ1, EQ2);
final List<Long> times = new ArrayList<>();
final CountDownLatch latch1 = new CountDownLatch(2);
final AtomicReference<ApplicationEvent> failEvent = new AtomicReference<>();
final CountDownLatch latch2 = new CountDownLatch(2);
container.setApplicationEventPublisher(event -> {
if (event instanceof ListenerContainerIdleEvent) {
times.add(System.currentTimeMillis());
latch1.countDown();
}
else {
failEvent.set((ApplicationEvent) event);
else if (event instanceof ListenerContainerConsumerTerminatedEvent) {
latch2.countDown();
}
});
Expand All @@ -339,8 +335,6 @@ public void testEvents() throws Exception {
assertThat(times.get(1) - times.get(0), greaterThanOrEqualTo(50L));
brokerRunning.deleteQueues(EQ1, EQ2);
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertNotNull(failEvent.get());
assertThat(failEvent.get(), instanceOf(ListenerContainerConsumerTerminatedEvent.class));
container.stop();
cf.destroy();
}
Expand Down

0 comments on commit 802a741

Please sign in to comment.