Skip to content

Commit 379ba34

Browse files
committed
Rework vertx-rx tests to reduce flakiness
1 parent ff38437 commit 379ba34

File tree

6 files changed

+192
-114
lines changed

6 files changed

+192
-114
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.vertx.reactive.server;
7+
8+
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
9+
10+
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
11+
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest;
12+
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
13+
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
14+
import io.vertx.core.DeploymentOptions;
15+
import io.vertx.core.Promise;
16+
import io.vertx.core.Vertx;
17+
import io.vertx.core.VertxOptions;
18+
import io.vertx.core.json.JsonObject;
19+
import io.vertx.reactivex.core.AbstractVerticle;
20+
import io.vertx.reactivex.ext.web.Router;
21+
import io.vertx.reactivex.ext.web.RoutingContext;
22+
import java.util.concurrent.CompletableFuture;
23+
import java.util.concurrent.TimeUnit;
24+
25+
abstract class AbstractVertxRxHttpServerTest extends AbstractHttpServerTest<Vertx> {
26+
static final String CONFIG_HTTP_SERVER_PORT = "http.server.port";
27+
28+
@Override
29+
protected Vertx setupServer() throws Exception {
30+
Vertx server =
31+
Vertx.vertx(
32+
new VertxOptions()
33+
// Useful for debugging:
34+
// .setBlockedThreadCheckInterval(Integer.MAX_VALUE)
35+
);
36+
CompletableFuture<Void> future = new CompletableFuture<>();
37+
server.deployVerticle(
38+
verticle().getName(),
39+
new DeploymentOptions()
40+
.setConfig(new JsonObject().put(CONFIG_HTTP_SERVER_PORT, port))
41+
.setInstances(3),
42+
result -> {
43+
if (!result.succeeded()) {
44+
throw new IllegalStateException("Cannot deploy server Verticle", result.cause());
45+
}
46+
future.complete(null);
47+
});
48+
49+
future.get(30, TimeUnit.SECONDS);
50+
return server;
51+
}
52+
53+
@Override
54+
protected void stopServer(Vertx vertx) {
55+
vertx.close();
56+
}
57+
58+
@Override
59+
protected void configure(HttpServerTestOptions options) {
60+
super.configure(options);
61+
62+
options.setTestPathParam(true);
63+
// server spans are ended inside the controller spans
64+
options.setVerifyServerSpanEndTime(false);
65+
options.setExpectedHttpRoute(
66+
(endpoint, method) -> {
67+
if (HttpConstants._OTHER.equals(method)) {
68+
return getContextPath() + endpoint.getPath();
69+
}
70+
return expectedHttpRoute(endpoint, method);
71+
});
72+
}
73+
74+
protected Class<? extends AbstractVerticle> verticle() {
75+
return VertxReactiveWebServer.class;
76+
}
77+
78+
public static class VertxReactiveWebServer extends AbstractVertxRxVerticle {
79+
@Override
80+
void handle(RoutingContext ctx, ServerEndpoint endpoint, Runnable action) {
81+
controller(endpoint, action::run);
82+
}
83+
84+
@Override
85+
public void start(Promise<Void> startFuture) {
86+
int port = config().getInteger(CONFIG_HTTP_SERVER_PORT);
87+
Router router = Router.router(vertx);
88+
89+
configure(router);
90+
router
91+
.route(EXCEPTION.getPath())
92+
.handler(
93+
ctx ->
94+
handle(
95+
ctx,
96+
EXCEPTION,
97+
() -> {
98+
throw new IllegalStateException(EXCEPTION.getBody());
99+
}));
100+
101+
vertx
102+
.createHttpServer()
103+
.requestHandler(router)
104+
.listen(port, httpServerAsyncResult -> startFuture.complete());
105+
}
106+
}
107+
}

instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxCircuitBreakerHttpServerTest.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
99

10+
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
11+
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
1012
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
1113
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
1214
import io.vertx.circuitbreaker.CircuitBreakerOptions;
@@ -15,8 +17,12 @@
1517
import io.vertx.reactivex.core.AbstractVerticle;
1618
import io.vertx.reactivex.ext.web.Router;
1719
import io.vertx.reactivex.ext.web.RoutingContext;
20+
import org.junit.jupiter.api.extension.RegisterExtension;
1821

19-
class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
22+
class VertxRxCircuitBreakerHttpServerTest extends AbstractVertxRxHttpServerTest {
23+
24+
@RegisterExtension
25+
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();
2026

2127
@Override
2228
protected void configure(HttpServerTestOptions options) {

instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxHttpServerTest.java

+1-56
Original file line numberDiff line numberDiff line change
@@ -7,76 +7,21 @@
77

88
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
99

10-
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
1110
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
12-
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest;
1311
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
14-
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
1512
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
16-
import io.vertx.core.DeploymentOptions;
1713
import io.vertx.core.Promise;
18-
import io.vertx.core.Vertx;
19-
import io.vertx.core.VertxOptions;
20-
import io.vertx.core.json.JsonObject;
2114
import io.vertx.reactivex.core.AbstractVerticle;
2215
import io.vertx.reactivex.ext.web.Router;
2316
import io.vertx.reactivex.ext.web.RoutingContext;
24-
import java.util.concurrent.CompletableFuture;
25-
import java.util.concurrent.TimeUnit;
2617
import org.junit.jupiter.api.extension.RegisterExtension;
2718

28-
class VertxRxHttpServerTest extends AbstractHttpServerTest<Vertx> {
29-
static final String CONFIG_HTTP_SERVER_PORT = "http.server.port";
19+
class VertxRxHttpServerTest extends AbstractVertxRxHttpServerTest {
3020

3121
@RegisterExtension
3222
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();
3323

3424
@Override
35-
protected Vertx setupServer() throws Exception {
36-
Vertx server =
37-
Vertx.vertx(
38-
new VertxOptions()
39-
// Useful for debugging:
40-
// .setBlockedThreadCheckInterval(Integer.MAX_VALUE)
41-
);
42-
CompletableFuture<Void> future = new CompletableFuture<>();
43-
server.deployVerticle(
44-
verticle().getName(),
45-
new DeploymentOptions()
46-
.setConfig(new JsonObject().put(CONFIG_HTTP_SERVER_PORT, port))
47-
.setInstances(3),
48-
result -> {
49-
if (!result.succeeded()) {
50-
throw new IllegalStateException("Cannot deploy server Verticle", result.cause());
51-
}
52-
future.complete(null);
53-
});
54-
55-
future.get(30, TimeUnit.SECONDS);
56-
return server;
57-
}
58-
59-
@Override
60-
protected void stopServer(Vertx vertx) {
61-
vertx.close();
62-
}
63-
64-
@Override
65-
protected void configure(HttpServerTestOptions options) {
66-
super.configure(options);
67-
68-
options.setTestPathParam(true);
69-
// server spans are ended inside the controller spans
70-
options.setVerifyServerSpanEndTime(false);
71-
options.setExpectedHttpRoute(
72-
(endpoint, method) -> {
73-
if (HttpConstants._OTHER.equals(method)) {
74-
return getContextPath() + endpoint.getPath();
75-
}
76-
return expectedHttpRoute(endpoint, method);
77-
});
78-
}
79-
8025
protected Class<? extends AbstractVerticle> verticle() {
8126
return VertxReactiveWebServer.class;
8227
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.vertx.reactive.server;
7+
8+
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
9+
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest;
10+
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
11+
import io.vertx.core.DeploymentOptions;
12+
import io.vertx.core.Vertx;
13+
import io.vertx.core.VertxOptions;
14+
import io.vertx.core.json.JsonObject;
15+
import io.vertx.reactivex.core.AbstractVerticle;
16+
import java.util.concurrent.CompletableFuture;
17+
import java.util.concurrent.TimeUnit;
18+
19+
abstract class AbstractVertxRxHttpServerTest extends AbstractHttpServerTest<Vertx> {
20+
static final String CONFIG_HTTP_SERVER_PORT = "http.server.port";
21+
22+
@Override
23+
protected Vertx setupServer() throws Exception {
24+
Vertx server =
25+
Vertx.vertx(
26+
new VertxOptions()
27+
// Useful for debugging:
28+
// .setBlockedThreadCheckInterval(Integer.MAX_VALUE)
29+
.setClusterPort(port));
30+
CompletableFuture<Void> future = new CompletableFuture<>();
31+
server.deployVerticle(
32+
verticle().getName(),
33+
new DeploymentOptions()
34+
.setConfig(new JsonObject().put(CONFIG_HTTP_SERVER_PORT, port))
35+
.setInstances(3),
36+
result -> {
37+
if (!result.succeeded()) {
38+
throw new IllegalStateException("Cannot deploy server Verticle", result.cause());
39+
}
40+
future.complete(null);
41+
});
42+
43+
future.get(30, TimeUnit.SECONDS);
44+
return server;
45+
}
46+
47+
@Override
48+
protected void stopServer(Vertx vertx) {
49+
vertx.close();
50+
}
51+
52+
@Override
53+
protected void configure(HttpServerTestOptions options) {
54+
super.configure(options);
55+
56+
options.setTestPathParam(true);
57+
// server spans are ended inside the controller spans
58+
options.setVerifyServerSpanEndTime(false);
59+
options.setExpectedHttpRoute(
60+
(endpoint, method) -> {
61+
if (HttpConstants._OTHER.equals(method)) {
62+
return getContextPath() + endpoint.getPath();
63+
}
64+
return expectedHttpRoute(endpoint, method);
65+
});
66+
}
67+
68+
protected abstract Class<? extends AbstractVerticle> verticle();
69+
}

instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxCircuitBreakerHttpServerTest.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
99

10+
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
11+
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
1012
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
1113
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
1214
import io.vertx.circuitbreaker.CircuitBreakerOptions;
@@ -15,8 +17,12 @@
1517
import io.vertx.reactivex.core.AbstractVerticle;
1618
import io.vertx.reactivex.ext.web.Router;
1719
import io.vertx.reactivex.ext.web.RoutingContext;
20+
import org.junit.jupiter.api.extension.RegisterExtension;
1821

19-
class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest {
22+
class VertxRxCircuitBreakerHttpServerTest extends AbstractVertxRxHttpServerTest {
23+
24+
@RegisterExtension
25+
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();
2026

2127
@Override
2228
protected void configure(HttpServerTestOptions options) {

instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/io/opentelemetry/javaagent/instrumentation/vertx/reactive/server/VertxRxHttpServerTest.java

+1-56
Original file line numberDiff line numberDiff line change
@@ -7,76 +7,21 @@
77

88
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
99

10-
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
1110
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
12-
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest;
1311
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
14-
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
1512
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
16-
import io.vertx.core.DeploymentOptions;
1713
import io.vertx.core.Future;
18-
import io.vertx.core.Vertx;
19-
import io.vertx.core.VertxOptions;
20-
import io.vertx.core.json.JsonObject;
2114
import io.vertx.reactivex.core.AbstractVerticle;
2215
import io.vertx.reactivex.ext.web.Router;
2316
import io.vertx.reactivex.ext.web.RoutingContext;
24-
import java.util.concurrent.CompletableFuture;
25-
import java.util.concurrent.TimeUnit;
2617
import org.junit.jupiter.api.extension.RegisterExtension;
2718

28-
class VertxRxHttpServerTest extends AbstractHttpServerTest<Vertx> {
29-
static final String CONFIG_HTTP_SERVER_PORT = "http.server.port";
19+
class VertxRxHttpServerTest extends AbstractVertxRxHttpServerTest {
3020

3121
@RegisterExtension
3222
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();
3323

3424
@Override
35-
protected Vertx setupServer() throws Exception {
36-
Vertx server =
37-
Vertx.vertx(
38-
new VertxOptions()
39-
// Useful for debugging:
40-
// .setBlockedThreadCheckInterval(Integer.MAX_VALUE)
41-
.setClusterPort(port));
42-
CompletableFuture<Void> future = new CompletableFuture<>();
43-
server.deployVerticle(
44-
verticle().getName(),
45-
new DeploymentOptions()
46-
.setConfig(new JsonObject().put(CONFIG_HTTP_SERVER_PORT, port))
47-
.setInstances(3),
48-
result -> {
49-
if (!result.succeeded()) {
50-
throw new IllegalStateException("Cannot deploy server Verticle", result.cause());
51-
}
52-
future.complete(null);
53-
});
54-
55-
future.get(30, TimeUnit.SECONDS);
56-
return server;
57-
}
58-
59-
@Override
60-
protected void stopServer(Vertx vertx) {
61-
vertx.close();
62-
}
63-
64-
@Override
65-
protected void configure(HttpServerTestOptions options) {
66-
super.configure(options);
67-
68-
options.setTestPathParam(true);
69-
// server spans are ended inside the controller spans
70-
options.setVerifyServerSpanEndTime(false);
71-
options.setExpectedHttpRoute(
72-
(endpoint, method) -> {
73-
if (HttpConstants._OTHER.equals(method)) {
74-
return getContextPath() + endpoint.getPath();
75-
}
76-
return expectedHttpRoute(endpoint, method);
77-
});
78-
}
79-
8025
protected Class<? extends AbstractVerticle> verticle() {
8126
return VertxReactiveWebServer.class;
8227
}

0 commit comments

Comments
 (0)