]> source.dussan.org Git - sonarqube.git/commitdiff
Add test for CommandExecutor timeout with new shell
authorJulien HENRY <julien.henry@sonarsource.com>
Wed, 27 May 2015 12:01:42 +0000 (14:01 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 27 May 2015 12:02:06 +0000 (14:02 +0200)
sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandExecutorTest.java

index f9b071cc929ca52e58309c641e2b70c82f7c0bc6..04e2f78be98b1fd35d27ec00cc17158a8ea16ac4 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.api.utils.command;
 
+import java.io.File;
+import java.io.IOException;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.junit.Before;
@@ -29,9 +31,6 @@ import org.junit.rules.TemporaryFolder;
 import org.junit.rules.TestName;
 import org.sonar.api.utils.System2;
 
-import java.io.File;
-import java.io.IOException;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
 
@@ -126,7 +125,7 @@ public class CommandExecutorTest {
     assertThat(log).contains("Environment variable: 2");
   }
 
-  @Test
+  @Test(timeout = 3000L)
   public void should_stop_after_timeout() throws IOException {
     try {
       String executable = getScript("forever");
@@ -137,6 +136,17 @@ public class CommandExecutorTest {
     }
   }
 
+  @Test(timeout = 3000L)
+  public void should_stop_after_timeout_and_new_shell() throws IOException {
+    try {
+      String executable = getScript("forever");
+      CommandExecutor.create().execute(Command.create(executable).setNewShell(true).setDirectory(workDir), 300L);
+      fail();
+    } catch (TimeoutException e) {
+      // ok
+    }
+  }
+
   @Test
   public void should_fail_if_script_not_found() {
     thrown.expect(CommandException.class);