From 491be234c6fcd7a9e3b88a719378451ba16fa990 Mon Sep 17 00:00:00 2001 From: Lutz Justen Date: Wed, 30 Nov 2022 09:27:57 +0100 Subject: [PATCH] "Proper" fix for "Input redirection is not supported" issue with timeout (#31) The issue was consistently reproducible by adding a sleep right after starting the process. Use ping instead of timeout now, because ping doesn't read user input. --- common/process_test.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/common/process_test.cc b/common/process_test.cc index 9ff9784..ed4f151 100644 --- a/common/process_test.cc +++ b/common/process_test.cc @@ -313,11 +313,10 @@ TEST_F(ProcessTest, LogOutputLevelDetection) { } TEST_F(ProcessTest, Terminate) { + // Use ping to simulate a sleep instead of timeout since timeout fails with + // "Input redirection is not supported". ProcessStartInfo start_info; - start_info.command = "timeout /T 30"; - // Prevents the process from shutting down immediately when run in background. - // https://www.ibm.com/support/pages/timeout-command-run-batch-job-exits-immediately-and-returns-error-input-redirection-not-supported-exiting-process-immediately - start_info.redirect_stdin = true; + start_info.command = "ping -n 30 127.0.0.1"; std::unique_ptr process = process_factory_.Create(start_info); EXPECT_OK(process->Start()); EXPECT_EQ(process->ExitCode(), Process::kExitCodeStillRunning); @@ -326,18 +325,17 @@ TEST_F(ProcessTest, Terminate) { } TEST_F(ProcessTest, TerminateAlreadyExited) { + // Use ping to simulate a sleep instead of timeout since timeout fails with + // "Input redirection is not supported". ProcessStartInfo start_info; - start_info.command = "timeout /T 30"; - // Prevents the process from shutting down immediately when run in background. - // https://www.ibm.com/support/pages/timeout-command-run-batch-job-exits-immediately-and-returns-error-input-redirection-not-supported-exiting-process-immediately - start_info.redirect_stdin = true; + start_info.command = "ping -n 30 127.0.0.1"; std::unique_ptr process = process_factory_.Create(start_info); EXPECT_OK(process->Start()); EXPECT_FALSE(process->HasExited()); bool terminated = false; Stopwatch sw; while (sw.ElapsedSeconds() < 5 && !terminated) { - terminated = TerminateProcessByName("timeout.exe"); + terminated = TerminateProcessByName("ping.exe"); if (!terminated) Util::Sleep(1); } EXPECT_TRUE(terminated);