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,23 +119,28 @@ class HibernateReactiveTest {
@Test @Test
void testStage() throws Exception { void testStage() throws Exception {
testing CountDownLatch latch = new CountDownLatch(1);
.runWithSpan( testing.runWithSpan(
"parent", "parent",
() -> () ->
stageSessionFactory Vertx.vertx()
.withSession( .getOrCreateContext()
session -> { .runOnContext(
if (!Span.current().getSpanContext().isValid()) { event ->
throw new IllegalStateException("missing parent span"); stageSessionFactory
} .withSession(
session -> {
if (!Span.current().getSpanContext().isValid()) {
throw new IllegalStateException("missing parent span");
}
return session return session
.find(Value.class, 1L) .find(Value.class, 1L)
.thenAccept(value -> testing.runWithSpan("callback", () -> {})); .thenAccept(
}) value -> testing.runWithSpan("callback", () -> {}));
.toCompletableFuture()) })
.get(30, TimeUnit.SECONDS); .thenAccept(unused -> latch.countDown())));
latch.await(30, TimeUnit.SECONDS);
assertTrace(); assertTrace();
} }