From fa38177033e96517e2956af60991881c5de163d9 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Wed, 15 Nov 2023 11:30:01 +0100 Subject: [PATCH] Make analytics tests more a bit more resilient We have seen several failures lately, let's hope this fixes it. --- .../analytics/AnalyticsServicePromptTest.java | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/independent-projects/tools/analytics-common/src/test/java/io/quarkus/analytics/AnalyticsServicePromptTest.java b/independent-projects/tools/analytics-common/src/test/java/io/quarkus/analytics/AnalyticsServicePromptTest.java index 07d3df954c868..dec63b23316c8 100644 --- a/independent-projects/tools/analytics-common/src/test/java/io/quarkus/analytics/AnalyticsServicePromptTest.java +++ b/independent-projects/tools/analytics-common/src/test/java/io/quarkus/analytics/AnalyticsServicePromptTest.java @@ -66,25 +66,36 @@ void testConsoleQuestion_no() throws IOException { @Test void testConsoleQuestion_promptTimeout() throws IOException { - System.setProperty("quarkus.analytics.prompt.timeout", "0"); - assertFalse(fileLocations.getLocalConfigFile().toFile().exists()); - service.buildAnalyticsUserInput((String prompt) -> { - assertEquals(ACCEPTANCE_PROMPT, prompt); - return "n"; - }); - assertFalse(fileLocations.getLocalConfigFile().toFile().exists()); - System.clearProperty("quarkus.analytics.prompt.timeout"); + try { + System.setProperty("quarkus.analytics.prompt.timeout", "0"); + assertFalse(fileLocations.getLocalConfigFile().toFile().exists()); + service.buildAnalyticsUserInput((String prompt) -> { + assertEquals(ACCEPTANCE_PROMPT, prompt); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return "n"; + }); + assertFalse(fileLocations.getLocalConfigFile().toFile().exists()); + } finally { + System.clearProperty("quarkus.analytics.prompt.timeout"); + } } @Test void testConsoleQuestion_AnalyticsDisabled() throws IOException { - System.setProperty("quarkus.analytics.disabled", "true"); - assertFalse(fileLocations.getLocalConfigFile().toFile().exists()); - service.buildAnalyticsUserInput((String prompt) -> { - fail("Prompt should be disabled"); - return "n"; - }); - assertFalse(fileLocations.getLocalConfigFile().toFile().exists()); - System.clearProperty("quarkus.analytics.disabled"); + try { + System.setProperty("quarkus.analytics.disabled", "true"); + assertFalse(fileLocations.getLocalConfigFile().toFile().exists()); + service.buildAnalyticsUserInput((String prompt) -> { + fail("Prompt should be disabled"); + return "n"; + }); + assertFalse(fileLocations.getLocalConfigFile().toFile().exists()); + } finally { + System.clearProperty("quarkus.analytics.disabled"); + } } }