diff --git a/test/libsinsp_e2e/subprocess.cpp b/test/libsinsp_e2e/subprocess.cpp index 62d45d8f0a..ab12303f8b 100644 --- a/test/libsinsp_e2e/subprocess.cpp +++ b/test/libsinsp_e2e/subprocess.cpp @@ -30,11 +30,13 @@ limitations under the License. #include #include -subprocess::subprocess(std::string command, std::vector arguments, bool start_now) - : m_pid(-1) +subprocess::subprocess(std::string command, std::vector arguments, + bool start_now, int retry_attempts): + m_pid(-1), + m_retry_attemps(retry_attempts), + m_command(command), + m_args(arguments) { - m_command = command; - m_args = arguments; if(start_now) { start(); @@ -60,20 +62,25 @@ void subprocess::wait_for_start() timeout.tv_usec = 0; int result = select(m_out_pipe[0] + 1, &read_set, nullptr, nullptr, &timeout); + int attempt = 0; - switch(result) + while(attempt < m_retry_attemps) { - case -1: - perror("select"); - break; - case 0: - std::cerr << "Timeout waiting for process to start." << std::endl; - break; - default: - if (!FD_ISSET(m_out_pipe[0], &read_set)) { - std::cerr << "Unexpected error during select." << std::endl; - } - break; + switch(result) + { + case -1: + perror("select"); + break; + case 0: + std::cerr << "Timeout waiting for process to start. Retry n." + << (attempt + 1) << "/" << m_retry_attemps << std::endl; + break; + default: + if (!FD_ISSET(m_out_pipe[0], &read_set)) { + std::cerr << "Unexpected error during select." << std::endl; + } + break; + } } } diff --git a/test/libsinsp_e2e/subprocess.h b/test/libsinsp_e2e/subprocess.h index 2c0345e552..ef9fe01ca1 100644 --- a/test/libsinsp_e2e/subprocess.h +++ b/test/libsinsp_e2e/subprocess.h @@ -31,8 +31,8 @@ limitations under the License. class subprocess { public: - - subprocess(std::string command, std::vector arguments, bool start_now=true); + subprocess(std::string command, std::vector arguments, + bool start_now=true, int retry_attempts=3); ~subprocess(); void wait_for_start(); @@ -51,6 +51,7 @@ class subprocess { pid_t m_pid; int m_in_pipe[2]; int m_out_pipe[2]; + int m_retry_attemps; std::ostream* m_in_stream; std::istream* m_out_stream;