From 135aa05b1412529f6793c26903d1ab9413f14dc6 Mon Sep 17 00:00:00 2001 From: pablo gonzalez granados Date: Thu, 28 Oct 2021 12:26:27 +0200 Subject: [PATCH] Fix Quarkus-cli flacky test on Quarkus start --- .../test/java/io/quarkus/qe/QuarkusCliClientIT.java | 13 +++++++++++-- .../java/io/quarkus/test/QuarkusCliClientIT.java | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/examples/quarkus-cli/src/test/java/io/quarkus/qe/QuarkusCliClientIT.java b/examples/quarkus-cli/src/test/java/io/quarkus/qe/QuarkusCliClientIT.java index 3afabd088..f0e1ab7df 100644 --- a/examples/quarkus-cli/src/test/java/io/quarkus/qe/QuarkusCliClientIT.java +++ b/examples/quarkus-cli/src/test/java/io/quarkus/qe/QuarkusCliClientIT.java @@ -3,7 +3,9 @@ import static io.quarkus.test.utils.AwaitilityUtils.untilAsserted; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.time.Duration; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Stream; import javax.inject.Inject; @@ -24,6 +26,7 @@ public class QuarkusCliClientIT { static final String RESTEASY_EXTENSION = "quarkus-resteasy"; static final String SMALLRYE_HEALTH_EXTENSION = "quarkus-smallrye-health"; + static final int CMD_DELAY_SEC = 3; @Inject static QuarkusCliClient cliClient; @@ -43,7 +46,7 @@ public void shouldCreateApplicationOnJvm() { } @Test - public void shouldAddAndRemoveExtensions() { + public void shouldAddAndRemoveExtensions() throws InterruptedException { // Create application QuarkusCliRestService app = cliClient.createApplication("app"); @@ -67,7 +70,7 @@ public void shouldAddAndRemoveExtensions() { assertTrue(result.isSuccessful(), SMALLRYE_HEALTH_EXTENSION + " was not uninstalled. Output: " + result.getOutput()); // The health endpoint should be now gone - app.start(); + startAfter(app, Duration.ofSeconds(CMD_DELAY_SEC)); untilAsserted(() -> app.given().get("/q/health").then().statusCode(HttpStatus.SC_NOT_FOUND)); } @@ -76,4 +79,10 @@ private void assertInstalledExtensions(QuarkusCliRestService app, String... expe Stream.of(expectedExtensions).forEach(expectedExtension -> assertTrue(extensions.contains(expectedExtension), expectedExtension + " not found in " + extensions)); } + + // https://github.com/quarkusio/quarkus/issues/21070 + private void startAfter(QuarkusCliRestService app, Duration duration) throws InterruptedException { + TimeUnit.SECONDS.sleep(duration.getSeconds()); + app.start(); + } } diff --git a/quarkus-test-cli/src/test/java/io/quarkus/test/QuarkusCliClientIT.java b/quarkus-test-cli/src/test/java/io/quarkus/test/QuarkusCliClientIT.java index 918d6e48e..aeb6d473e 100644 --- a/quarkus-test-cli/src/test/java/io/quarkus/test/QuarkusCliClientIT.java +++ b/quarkus-test-cli/src/test/java/io/quarkus/test/QuarkusCliClientIT.java @@ -5,7 +5,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.time.Duration; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Stream; import javax.inject.Inject; @@ -31,6 +33,7 @@ public class QuarkusCliClientIT { static final String RESTEASY_SPRING_WEB_EXTENSION = "quarkus-spring-web"; static final String RESTEASY_EXTENSION = "quarkus-resteasy"; static final String SMALLRYE_HEALTH_EXTENSION = "quarkus-smallrye-health"; + static final int CMD_DELAY_SEC = 3; @Inject static QuarkusCliClient cliClient; @@ -85,7 +88,7 @@ public void shouldCreateApplicationWithCodeStarter() { } @Test - public void shouldAddAndRemoveExtensions() { + public void shouldAddAndRemoveExtensions() throws InterruptedException { // Create application QuarkusCliRestService app = cliClient.createApplication("app"); @@ -109,7 +112,7 @@ public void shouldAddAndRemoveExtensions() { assertTrue(result.isSuccessful(), SMALLRYE_HEALTH_EXTENSION + " was not uninstalled. Output: " + result.getOutput()); // The health endpoint should be now gone - app.start(); + startAfter(app, Duration.ofSeconds(CMD_DELAY_SEC)); untilAsserted(() -> app.given().get("/q/health").then().statusCode(HttpStatus.SC_NOT_FOUND)); } @@ -118,4 +121,10 @@ private void assertInstalledExtensions(QuarkusCliRestService app, String... expe Stream.of(expectedExtensions).forEach(expectedExtension -> assertTrue(extensions.contains(expectedExtension), expectedExtension + " not found in " + extensions)); } + + // https://github.com/quarkusio/quarkus/issues/21070 + private void startAfter(QuarkusCliRestService app, Duration duration) throws InterruptedException { + TimeUnit.SECONDS.sleep(duration.getSeconds()); + app.start(); + } }