Skip to content

Commit 0eed1f6

Browse files
committed
start appserver only once
1 parent 7507e95 commit 0eed1f6

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

smoke-tests/src/main/java/io/opentelemetry/smoketest/SmokeTestInstrumentationExtension.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,15 @@ public Set<String> getSpanTraceIds() {
142142
}
143143

144144
public SmokeTestOutput start(T arg) {
145-
autoCleanup.deferCleanup(() -> containerManager.stopTarget());
145+
autoCleanup.deferCleanup(() -> stop());
146+
return startWithoutCleanup(arg);
147+
}
148+
149+
public void stop() {
150+
containerManager.stopTarget();
151+
}
146152

153+
public SmokeTestOutput startWithoutCleanup(T arg) {
147154
return new SmokeTestOutput(
148155
this,
149156
containerManager.startTarget(

smoke-tests/src/test/java/io/opentelemetry/smoketest/appserver/AppServerTest.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@
2626
import io.opentelemetry.testing.internal.armeria.common.HttpMethod;
2727
import io.opentelemetry.testing.internal.armeria.common.RequestHeaders;
2828
import java.util.List;
29+
30+
import org.junit.jupiter.api.AfterAll;
2931
import org.junit.jupiter.api.BeforeEach;
3032
import org.junit.jupiter.api.Test;
3133

3234
public abstract class AppServerTest {
3335
protected boolean isWindows;
3436
protected String serverVersion;
37+
private static SmokeTestInstrumentationExtension<AppServerImage> started;
3538

3639
@BeforeEach
3740
void setUp() {
41+
if (started != null) {
42+
return;
43+
}
44+
3845
var appServer = getClass().getAnnotation(AppServer.class);
3946
if (appServer == null) {
4047
throw new IllegalStateException(
@@ -49,7 +56,17 @@ void setUp() {
4956
assumeFalse(isWindows && jdk.endsWith("-openj9"));
5057

5158
serverVersion = appServer.version();
52-
testing().start(new AppServerImage(jdk, serverVersion, isWindows));
59+
testing().startWithoutCleanup(new AppServerImage(jdk, serverVersion, isWindows));
60+
61+
started = testing();
62+
}
63+
64+
@AfterAll
65+
static void afterAll() {
66+
if (started != null) {
67+
started.stop();
68+
started = null;
69+
}
5370
}
5471

5572
protected abstract SmokeTestInstrumentationExtension<AppServerImage> testing();
@@ -136,7 +153,9 @@ void testStaticFileNotFound() {
136153
trace ->
137154
trace.hasSpansSatisfyingExactly(
138155
span -> assertServerSpan(span, path),
139-
span -> span.hasName("HttpServletResponseWrapper.sendError").hasKind(SpanKind.INTERNAL)));
156+
span ->
157+
span.hasName("HttpServletResponseWrapper.sendError")
158+
.hasKind(SpanKind.INTERNAL)));
140159
}
141160

142161
@Test
@@ -148,9 +167,7 @@ void testRequestForWebInfWebXml() {
148167

149168
testing()
150169
.waitAndAssertTraces(
151-
trace ->
152-
trace.hasSpansSatisfyingExactly(
153-
span -> assertServerSpan(span, path)));
170+
trace -> trace.hasSpansSatisfyingExactly(span -> assertServerSpan(span, path)));
154171
}
155172

156173
@Test
@@ -184,9 +201,7 @@ void testRequestOutsideDeployedApplication() {
184201

185202
testing()
186203
.waitAndAssertTraces(
187-
trace ->
188-
trace.hasSpansSatisfyingExactly(
189-
span -> assertServerSpan(span, path)));
204+
trace -> trace.hasSpansSatisfyingExactly(span -> assertServerSpan(span, path)));
190205
}
191206

192207
@Test

0 commit comments

Comments
 (0)