Skip to content

Commit 68da349

Browse files
authored
Fix flaky hibernate reactive test (#9338)
1 parent bebd819 commit 68da349

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

instrumentation/hibernate/hibernate-reactive-1.0/javaagent/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ testing {
3838
implementation("org.hibernate.reactive:hibernate-reactive-core:1.0.0.Final")
3939
implementation("io.vertx:vertx-pg-client:4.1.5")
4040
}
41+
compileOnly("io.vertx:vertx-codegen:4.1.5")
4142
}
4243
}
4344

instrumentation/hibernate/hibernate-reactive-1.0/javaagent/src/hibernateReactive1Test/java/io/opentelemetry/javaagent/instrumentation/hibernate/reactive/v1_0/HibernateReactiveTest.java

+24-17
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import io.opentelemetry.api.trace.SpanKind;
1919
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
2020
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
21+
import io.vertx.core.Vertx;
2122
import java.time.Duration;
23+
import java.util.concurrent.CountDownLatch;
2224
import java.util.concurrent.TimeUnit;
2325
import javax.persistence.EntityManagerFactory;
2426
import javax.persistence.Persistence;
@@ -117,23 +119,28 @@ void testMutiny() {
117119

118120
@Test
119121
void testStage() throws Exception {
120-
testing
121-
.runWithSpan(
122-
"parent",
123-
() ->
124-
stageSessionFactory
125-
.withSession(
126-
session -> {
127-
if (!Span.current().getSpanContext().isValid()) {
128-
throw new IllegalStateException("missing parent span");
129-
}
130-
131-
return session
132-
.find(Value.class, 1L)
133-
.thenAccept(value -> testing.runWithSpan("callback", () -> {}));
134-
})
135-
.toCompletableFuture())
136-
.get(30, TimeUnit.SECONDS);
122+
CountDownLatch latch = new CountDownLatch(1);
123+
testing.runWithSpan(
124+
"parent",
125+
() ->
126+
Vertx.vertx()
127+
.getOrCreateContext()
128+
.runOnContext(
129+
event ->
130+
stageSessionFactory
131+
.withSession(
132+
session -> {
133+
if (!Span.current().getSpanContext().isValid()) {
134+
throw new IllegalStateException("missing parent span");
135+
}
136+
137+
return session
138+
.find(Value.class, 1L)
139+
.thenAccept(
140+
value -> testing.runWithSpan("callback", () -> {}));
141+
})
142+
.thenAccept(unused -> latch.countDown())));
143+
latch.await(30, TimeUnit.SECONDS);
137144

138145
assertTrace();
139146
}

0 commit comments

Comments
 (0)