From 17e7570d600eed5c8183a4956586372585a4e326 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 9 Jul 2014 12:11:59 +0200 Subject: [PATCH] Fix stability of CommandExecutorTest --- .../org/sonar/api/utils/command/CommandExecutorTest.java | 9 ++------- sonar-plugin-api/src/test/scripts/forever.sh | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandExecutorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandExecutorTest.java index b8d4de67865..0dcba90e1ed 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandExecutorTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandExecutorTest.java @@ -128,17 +128,12 @@ public class CommandExecutorTest { @Test public void should_stop_after_timeout() throws IOException { - String executable = getScript("forever"); - long start = System.currentTimeMillis(); try { + String executable = getScript("forever"); CommandExecutor.create().execute(Command.create(executable).setDirectory(workDir), 300L); fail(); } catch (TimeoutException e) { - long duration = System.currentTimeMillis() - start; - // Future.get(), which is used by CommandExecutor, has not a precise timeout. - // See http://stackoverflow.com/questions/23199820/future-get-timeout-precision-and-possible-alternatives - // The deviation seems to be in both directions, so it implies to test something like >270ms instead of >300ms - assertThat(duration).as(e.getMessage()).isGreaterThan(250L); + // ok } } diff --git a/sonar-plugin-api/src/test/scripts/forever.sh b/sonar-plugin-api/src/test/scripts/forever.sh index d7b6a9b38fd..b05525430d5 100755 --- a/sonar-plugin-api/src/test/scripts/forever.sh +++ b/sonar-plugin-api/src/test/scripts/forever.sh @@ -2,5 +2,5 @@ while test "notempty" do - sleep 1 + sleep 5s done -- 2.39.5