Skip to content
Snippets Groups Projects
Commit cb92b7ca authored by brinn's avatar brinn
Browse files

add: test case with a hanging process which creates lots of output on stdout

SVN: 18673
parent 367d95d1
No related branches found
No related tags found
No related merge requests found
...@@ -52,17 +52,17 @@ public class ProcessExecutionHelperTest ...@@ -52,17 +52,17 @@ public class ProcessExecutionHelperTest
private static final long WATCHDOG_WAIT_MILLIS = 1000L; private static final long WATCHDOG_WAIT_MILLIS = 1000L;
private static final Logger machineLog = private static final Logger machineLog = LogFactory.getLogger(LogCategory.MACHINE,
LogFactory.getLogger(LogCategory.MACHINE, ProcessExecutionHelperTest.class); ProcessExecutionHelperTest.class);
private static final Logger operationLog = private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION,
LogFactory.getLogger(LogCategory.OPERATION, ProcessExecutionHelperTest.class); ProcessExecutionHelperTest.class);
private static final File unitTestRootDirectory = private static final File unitTestRootDirectory = new File("targets" + File.separator
new File("targets" + File.separator + "unit-test-wd"); + "unit-test-wd");
private static final File workingDirectory = private static final File workingDirectory = new File(unitTestRootDirectory,
new File(unitTestRootDirectory, "ProcessExecutionHelperTest"); "ProcessExecutionHelperTest");
private File createExecutable(String name, String... lines) throws IOException, private File createExecutable(String name, String... lines) throws IOException,
InterruptedException InterruptedException
...@@ -92,6 +92,12 @@ public class ProcessExecutionHelperTest ...@@ -92,6 +92,12 @@ public class ProcessExecutionHelperTest
+ (millisToSleep / 1000.0f), "exit 0"); + (millisToSleep / 1000.0f), "exit 0");
} }
private File createExecutableEndlessLoop(String name) throws IOException, InterruptedException
{
return createExecutable(name, "#! /bin/sh",
"n=1; while [ 1 ]; do echo $n; n=$(($n+1)); done");
}
@BeforeClass @BeforeClass
public void init() public void init()
{ {
...@@ -278,6 +284,21 @@ public class ProcessExecutionHelperTest ...@@ -278,6 +284,21 @@ public class ProcessExecutionHelperTest
assertEquals(sleepyMessage, result.getOutput().get(0)); assertEquals(sleepyMessage, result.getOutput().get(0));
} }
@Test(groups =
{ "requires_unix", "slow" })
public void testHangingExecLotsOfOutputOnStdOut() throws Exception
{
final File dummyExec = createExecutableEndlessLoop("iHang.sh");
final ProcessResult result =
ProcessExecutionHelper.run(Arrays.asList(dummyExec.getAbsolutePath()),
operationLog, machineLog, WATCHDOG_WAIT_MILLIS);
assertTrue(result.isTimedOut());
assertFalse(result.isOK());
assertTrue(Integer.toString(result.getOutput().size()), result.getOutput().size() > 100);
assertEquals(Integer.toString(result.getOutput().size()),
result.getOutput().get(result.getOutput().size() - 1));
}
@Test(groups = @Test(groups =
{ "requires_unix", "slow" }) { "requires_unix", "slow" })
public void testTryExecutionReadProcessOutput() throws Exception public void testTryExecutionReadProcessOutput() throws Exception
...@@ -312,8 +333,8 @@ public class ProcessExecutionHelperTest ...@@ -312,8 +333,8 @@ public class ProcessExecutionHelperTest
operationLog, machineLog); operationLog, machineLog);
result.log(); result.log();
assertFalse(result.isRun()); assertFalse(result.isRun());
assertTrue(result.getStartupFailureMessage(), result.getStartupFailureMessage().indexOf( assertTrue(result.getStartupFailureMessage(),
"some_non_existent_executable") >= 0); result.getStartupFailureMessage().indexOf("some_non_existent_executable") >= 0);
} }
@Test(groups = @Test(groups =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment