Skip to content

Commit 2933b82

Browse files
author
Andrzej Religa
committed
Bug#36253070 Router tests are failing on mac14 on pb2
Post-push fix: -reenabled corefiles on macoOS -initializing the logger in mysql_mock_server before the singal handler to avoid std::exception when it logs -removing the NOTE about failed setrlimit from the process output to avoid failures caused by it's random occurences Change-Id: If129580c86cb9261edaf1433ce33b9ed6135584f
1 parent db16967 commit 2933b82

File tree

6 files changed

+53
-53
lines changed

6 files changed

+53
-53
lines changed

router/src/mock_server/src/main.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,6 @@ class MysqlServerMockFrontend {
120120
bool is_print_and_exit() { return do_print_and_exit_; }
121121

122122
void run() {
123-
signal_handler_.register_ignored_signals_handler();
124-
signal_handler_.block_all_nonfatal_signals();
125-
signal_handler_.register_fatal_signal_handler(config_.core_file);
126-
signal_handler_.spawn_signal_handler_thread();
127-
#ifdef _WIN32
128-
signal_handler_.register_ctrl_c_handler();
129-
#endif
130-
131123
init_DIM();
132124
std::unique_ptr<mysql_harness::LoaderConfig> loader_config(
133125
new mysql_harness::LoaderConfig(mysql_harness::Config::allow_keys));
@@ -168,6 +160,15 @@ class MysqlServerMockFrontend {
168160
const std::string logfile_name = "mock_server_" + config_.port + ".log";
169161
logger_conf.add("filename", logfile_name);
170162

163+
// initialize the signal handler
164+
signal_handler_.register_ignored_signals_handler();
165+
signal_handler_.block_all_nonfatal_signals();
166+
signal_handler_.register_fatal_signal_handler(config_.core_file);
167+
signal_handler_.spawn_signal_handler_thread();
168+
#ifdef _WIN32
169+
signal_handler_.register_ctrl_c_handler();
170+
#endif
171+
171172
// assume all path relative to the installed binary
172173
auto plugin_dir = mysql_harness::get_plugin_dir(origin_dir_.str());
173174
loader_config->set_default("plugin_folder", plugin_dir);

router/tests/component/test_mock_server.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,13 +1090,6 @@ struct MockServerCoreTestParam {
10901090
ExitStatus expected_exit_status_;
10911091
};
10921092

1093-
#ifndef __APPLE__
1094-
// enabling core dump on pb2 macos14 causes random (but often):
1095-
// MySQLRouter:
1096-
// NOTE: core-file requested, but resource-limits say core-files are
1097-
// disabled for this process ('ulimit -c' is '0')
1098-
// mysql_mock_server:
1099-
// std::exception
11001093
class MockServerCoreTest
11011094
: public RouterComponentTest,
11021095
public ::testing::WithParamInterface<MockServerCoreTestParam> {};
@@ -1188,8 +1181,6 @@ INSTANTIATE_TEST_SUITE_P(Spec, MockServerCoreTest,
11881181
::testing::ValuesIn(mock_server_core_test_param),
11891182
[](const auto &info) { return info.param.test_name; });
11901183

1191-
#endif // __APPLE__
1192-
11931184
// session-tracker
11941185

11951186
struct MockServerCommandTestParam {

router/tests/component/test_pidfile.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -479,19 +479,19 @@ INSTANTIATE_TEST_SUITE_P(
479479
// shell does, so this should be identical to the quoted TS_FR10_02
480480
// case.
481481
PidFileOptionErrorParams(
482-
"", "^Error: Invalid empty value for --pid-file option"),
482+
"", "Error: Invalid empty value for --pid-file option"),
483483
// readonly dir : TS_FR11_01 (M)
484484
PidFileOptionErrorParams(
485485
mysql_harness::Path(FOO).join(READONLY_FOLDER).c_str(),
486-
"^Error: Failed writing PID to .*/foo/readonly':.*"),
486+
"Error: Failed writing PID to .*/foo/readonly':.*"),
487487
// readonly file : TS_FR11_02 (M)
488488
PidFileOptionErrorParams(
489489
mysql_harness::Path(FOO).join(READONLY_FILE).c_str(),
490-
"^Error: Failed writing PID to .*/foo/readonly.pid':.*"),
490+
"Error: Failed writing PID to .*/foo/readonly.pid':.*"),
491491
// nonexisting dir : TS_FR11_03 (M)
492492
PidFileOptionErrorParams(
493493
mysql_harness::Path(FOO).join(NONEXISTING).join(PIDFILE).c_str(),
494-
"^Error: Failed writing PID to "
494+
"Error: Failed writing PID to "
495495
".*/foo/nonexisting/mysqlrouter.pid':.*")));
496496

497497
/**
@@ -587,7 +587,7 @@ TEST_P(RouterPidfileOptionCfgValueTestError, PidFileOptionCfgValueTestError) {
587587

588588
// expect error
589589
EXPECT_TRUE(
590-
router.expect_output("^Error: PID filename '.*' is illegal", true));
590+
router.expect_output("Error: PID filename '.*' is illegal", true));
591591
}
592592

593593
INSTANTIATE_TEST_SUITE_P(PidFileOptionCfgValueTestError,
@@ -631,7 +631,7 @@ TEST_P(RouterPidfileOptionEnvValueTestError, PidFileOptionEnvValueTestError) {
631631

632632
// expect error
633633
EXPECT_TRUE(
634-
router.expect_output("^Error: PID filename '.*' is illegal", true));
634+
router.expect_output("Error: PID filename '.*' is illegal", true));
635635
}
636636

637637
INSTANTIATE_TEST_SUITE_P(PidFileOptionEnvValueTestError,
@@ -784,7 +784,7 @@ INSTANTIATE_TEST_SUITE_P(PidFileOptionSupremacyCornerCaseTest,
784784
// empty value : TS_FR03_02
785785
PidFileOptionSupremacyCornerCaseParams(
786786
"pid_file = ",
787-
"^Error: PID filename '.*' is illegal.")));
787+
"Error: PID filename '.*' is illegal.")));
788788

789789
/**
790790
* @test
@@ -840,8 +840,8 @@ TEST_P(RouterPidfileOptionExistsTest, PidFileOptionExistsTest) {
840840
}
841841

842842
// expect error
843-
EXPECT_TRUE(router.expect_output(
844-
"^Error: PID file .* found. Already running?", true));
843+
EXPECT_TRUE(
844+
router.expect_output("Error: PID file .* found. Already running?", true));
845845

846846
// pid-file still exists
847847
EXPECT_TRUE(fullpath.exists()) << fullpath.str();

router/tests/component/test_router_stacktrace.cc

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#include "test/temp_directory.h"
4646

4747
namespace {
48-
49-
#ifndef __APPLE__
5048
constexpr const int abrt_status{
5149
#ifdef _WIN32
5250
0x00000102 // STATUS_TIMEOUT
@@ -65,7 +63,6 @@ constexpr const int segv_status{
6563
#endif
6664
};
6765

68-
#endif
6966
#endif
7067

7168
} // namespace
@@ -91,14 +88,6 @@ TEST_F(RouterStacktraceTest, help_has_core_file) {
9188
EXPECT_THAT(r.get_full_output(), ::testing::HasSubstr(" --core-file"));
9289
}
9390

94-
#ifndef __APPLE__
95-
// enabling core dump on pb2 macos14 causes random (but often):
96-
// MySQLRouter:
97-
// NOTE: core-file requested, but resource-limits say core-files are
98-
// disabled for this process ('ulimit -c' is '0')
99-
// mysql_mock_server:
100-
// std::exception
101-
10291
// TS_1_2
10392
TEST_F(RouterStacktraceTest, bootstrap_with_core_file) {
10493
auto mock_port = port_pool_.get_next_available();
@@ -583,8 +572,6 @@ TEST_F(RouterStacktraceTest, core_file_0) {
583572

584573
#endif // !defined(HAVE_ASAN) && !defined(HAVE_UBSAN)
585574

586-
#endif // __APPLE__
587-
588575
int main(int argc, char *argv[]) {
589576
init_windows_sockets();
590577
ProcessManager::set_origin(Path(argv[0]).dirname());

router/tests/helpers/process_manager.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,8 @@ class ProcessManager {
120120
return *this;
121121
}
122122

123-
Spawner &with_core_dump([[maybe_unused]] bool dump_core) {
124-
#ifndef __APPLE__
123+
Spawner &with_core_dump(bool dump_core) {
125124
with_core_ = dump_core;
126-
#else
127-
// enabling core dump on pb2 macos14 causes random (but often):
128-
// MySQLRouter:
129-
// NOTE: core-file requested, but resource-limits say core-files are
130-
// disabled for this process ('ulimit -c' is '0')
131-
// mysql_mock_server:
132-
// std::exception
133-
with_core_ = false;
134-
#endif
135-
136125
return *this;
137126
}
138127

router/tests/helpers/process_wrapper.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#ifndef _PROCESS_WRAPPER_H_
2626
#define _PROCESS_WRAPPER_H_
2727

28+
#include "mysql/harness/string_utils.h" // split_string
29+
#include "mysql/harness/utility/string.h" // starts_with
2830
#include "process_launcher.h"
2931
#include "router_test_helpers.h"
3032

@@ -87,8 +89,38 @@ class ProcessWrapper {
8789
* of calling this method.
8890
*/
8991
std::string get_full_output() {
90-
std::lock_guard<std::mutex> output_lock(output_mtx_);
91-
return execute_output_raw_;
92+
using mysql_harness::utility::starts_with;
93+
std::vector<std::string> lines;
94+
std::string result;
95+
96+
{
97+
std::lock_guard<std::mutex> output_lock(output_mtx_);
98+
lines = mysql_harness::split_string(execute_output_raw_, '\n');
99+
}
100+
101+
if (lines.size() > 1) {
102+
// remove last empty line
103+
lines.pop_back();
104+
}
105+
106+
bool core_file_req_failed{false};
107+
for (const std::string &line : lines) {
108+
// setrlimit sometimes fails on pb2 macos, resulting in additional,
109+
// unwanted console output that we remove here
110+
if (starts_with(line,
111+
"NOTE: core-file requested, but resource-limits say")) {
112+
core_file_req_failed = true;
113+
continue;
114+
}
115+
if (core_file_req_failed &&
116+
starts_with(line, "stopping to log to the console") &&
117+
lines.size() == 2) {
118+
continue;
119+
}
120+
result += (line + "\n");
121+
}
122+
123+
return result;
92124
}
93125

94126
/** @brief returns the content of the process app logfile as a string

0 commit comments

Comments
 (0)