Skip to content

Commit 98c7a77

Browse files
committed
Bug#35882384 stdout, logs not collected at unexpected process end
At test-end, the TearDown checks for a testing::FatalFailures() and dumps the logs and stdout of the known processes. But if tests call ProcessManager::clear() release processes early, the "dump logs at fatal failure at test-end" will show no logs for those "cleared" processes. Change ====== - dump the logs and stdout when the unexpected process termination happens. Change-Id: Iffede15f3be1352124f607e2e323630e83b0f23d
1 parent d9d9ca7 commit 98c7a77

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

router/tests/helpers/process_manager.cc

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include "mysqlrouter/rest_client.h"
6565
#include "mysqlrouter/utils.h"
6666
#include "process_launcher.h"
67+
#include "process_wrapper.h"
6768
#include "random_generator.h"
6869

6970
#ifdef USE_STD_REGEX
@@ -648,22 +649,31 @@ void ProcessManager::terminate_all_still_alive() {
648649
}
649650
}
650651

652+
std::string ProcessManager::dump(ProcessWrapper &proc) {
653+
std::stringstream ss;
654+
655+
ss << "# Process: (pid=" << proc.get_pid() << ")\n"
656+
<< proc.get_command_line() << "\n\n";
657+
658+
auto output = proc.get_current_output();
659+
if (!output.empty()) {
660+
ss << "## Console output:\n\n" << output << "\n";
661+
}
662+
663+
auto log_content = proc.get_logfile_content("", "", 500);
664+
if (!log_content.empty()) {
665+
ss << "## Log content:\n\n" << log_content << "\n";
666+
}
667+
668+
return ss.str();
669+
}
670+
651671
void ProcessManager::dump_all() {
652672
std::stringstream ss;
653673
for (const auto &proc_and_exit_code : processes_) {
654674
const auto &proc = std::get<0>(proc_and_exit_code);
655-
ss << "# Process: (pid=" << proc->get_pid() << ")\n"
656-
<< proc->get_command_line() << "\n\n";
657675

658-
auto output = proc->get_current_output();
659-
if (!output.empty()) {
660-
ss << "## Console output:\n\n" << output << "\n";
661-
}
662-
663-
auto log_content = proc->get_logfile_content("", "", 500);
664-
if (!log_content.empty()) {
665-
ss << "## Log content:\n\n" << log_content << "\n";
666-
}
676+
ss << dump(*proc);
667677
}
668678

669679
FAIL() << ss.str();
@@ -736,7 +746,9 @@ void ProcessManager::check_exit_code(ProcessWrapper &process,
736746
if (dump_res) std::cerr << *dump_res;
737747

738748
ASSERT_EQ(expected_exit_status, result)
739-
<< "Process " << process.get_pid() << " terminated with " << result;
749+
<< "Process " << process.get_pid() << " terminated with " << result
750+
<< "\n"
751+
<< dump(process);
740752
} else if (auto sig = result.stopped()) {
741753
ASSERT_EQ(expected_exit_status, result)
742754
<< "Process " << process.get_pid() << " stopped with " << result;

router/tests/helpers/process_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ class ProcessManager {
237237
ProcessWrapper &process, exit_status_type exit_status = EXIT_SUCCESS,
238238
std::chrono::milliseconds timeout = kDefaultWaitForExitTimeout);
239239

240+
std::string dump(ProcessWrapper &proccess);
241+
240242
void dump_all();
241243

242244
/**

0 commit comments

Comments
 (0)