Fix flaky hibernate reactive test (#9338)

This commit is contained in:
Lauri Tulmin 2023-08-29 20:19:13 +03:00 committed by GitHub
parent bebd819277
commit 68da349386
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 16 deletions

View File

@ -38,6 +38,7 @@ testing {
implementation("org.hibernate.reactive:hibernate-reactive-core:1.0.0.Final") implementation("org.hibernate.reactive:hibernate-reactive-core:1.0.0.Final")
implementation("io.vertx:vertx-pg-client:4.1.5") implementation("io.vertx:vertx-pg-client:4.1.5")
} }
compileOnly("io.vertx:vertx-codegen:4.1.5")
} }
} }

View File

@ -18,7 +18,9 @@ import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.vertx.core.Vertx;
import java.time.Duration; import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence; import javax.persistence.Persistence;
@ -117,10 +119,14 @@ class HibernateReactiveTest {
@Test @Test
void testStage() throws Exception { void testStage() throws Exception {
testing CountDownLatch latch = new CountDownLatch(1);
.runWithSpan( testing.runWithSpan(
"parent", "parent",
() -> () ->
Vertx.vertx()
.getOrCreateContext()
.runOnContext(
event ->
stageSessionFactory stageSessionFactory
.withSession( .withSession(
session -> { session -> {
@ -130,10 +136,11 @@ class HibernateReactiveTest {
return session return session
.find(Value.class, 1L) .find(Value.class, 1L)
.thenAccept(value -> testing.runWithSpan("callback", () -> {})); .thenAccept(
value -> testing.runWithSpan("callback", () -> {}));
}) })
.toCompletableFuture()) .thenAccept(unused -> latch.countDown())));
.get(30, TimeUnit.SECONDS); latch.await(30, TimeUnit.SECONDS);
assertTrace(); assertTrace();
} }