From 21904e75a3a2b839a797c948c9c16c3d2ddd03e3 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Fri, 7 Feb 2025 00:43:23 +0900 Subject: [PATCH] Fix flakiness in JmsInstrumentationTests.shouldInstrumentMessageListener() Signed-off-by: Johnny Lim --- .../binder/jms/JmsInstrumentationTests.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/micrometer-test/src/test/java/io/micrometer/core/instrument/binder/jms/JmsInstrumentationTests.java b/micrometer-test/src/test/java/io/micrometer/core/instrument/binder/jms/JmsInstrumentationTests.java index f795eb9905..c5271a2d64 100644 --- a/micrometer-test/src/test/java/io/micrometer/core/instrument/binder/jms/JmsInstrumentationTests.java +++ b/micrometer-test/src/test/java/io/micrometer/core/instrument/binder/jms/JmsInstrumentationTests.java @@ -15,6 +15,7 @@ */ package io.micrometer.core.instrument.binder.jms; +import java.time.Duration; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.stream.Stream; @@ -35,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.awaitility.Awaitility.await; /** * Tests for {@link JmsInstrumentation}. @@ -134,10 +136,11 @@ void shouldInstrumentMessageListener() throws Exception { MessageProducer producer = session.createProducer(topic); producer.send(session.createTextMessage("test send")); assertThat(latch.await(2, TimeUnit.SECONDS)).isTrue(); - TestObservationRegistryAssert.assertThat(registry) - .hasObservationWithNameEqualTo("jms.message.process") - .that() - .hasContextualNameEqualTo("test.send process"); + await().atMost(Duration.ofSeconds(1)) + .untilAsserted(() -> TestObservationRegistryAssert.assertThat(registry) + .hasObservationWithNameEqualTo("jms.message.process") + .that() + .hasContextualNameEqualTo("test.send process")); } }