From fca11f992a26bc4aa0bb8e3e14045fae4db4c3c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 13 Nov 2017 15:47:25 +0200 Subject: [PATCH] Fix verify_master_failure The test expected the wrong error message to be in the log. To better cope with changes in the text, the test now uses a regular expression to do the matching. --- maxscale-system-test/testconnections.cpp | 15 +++++++++++++++ maxscale-system-test/testconnections.h | 17 +++++++++++++++++ maxscale-system-test/verify_master_failure.cpp | 5 +++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/maxscale-system-test/testconnections.cpp b/maxscale-system-test/testconnections.cpp index ce8cae0f1..fcc411239 100644 --- a/maxscale-system-test/testconnections.cpp +++ b/maxscale-system-test/testconnections.cpp @@ -1183,6 +1183,21 @@ int TestConnections::start_mm() return global_result; } +bool TestConnections::log_matches(const char* pattern) +{ + return ssh_maxscale(true, "grep '%s' /var/log/maxscale/maxscale*.log", pattern) == 0; +} + +void TestConnections::log_includes(const char* pattern) +{ + add_result(!log_matches(pattern), "Log does not match pattern '%s'", pattern); +} + +void TestConnections::log_excludes(const char* pattern) +{ + add_result(log_matches(pattern), "Log matches pattern '%s'", pattern); +} + void TestConnections::check_log_err(const char * err_msg, bool expected) { diff --git a/maxscale-system-test/testconnections.h b/maxscale-system-test/testconnections.h index 8607b000b..cd2dfb202 100644 --- a/maxscale-system-test/testconnections.h +++ b/maxscale-system-test/testconnections.h @@ -43,6 +43,7 @@ class TestConnections private: /** Whether timeouts are enabled or not */ bool enable_timeouts; + bool log_matches(const char* pattern); public: /** * @brief TestConnections constructor: reads environmental variables, copies MaxScale.cnf for MaxScale machine @@ -634,6 +635,22 @@ public: */ void check_log_err(const char * err_msg, bool expected); + /** + * @brief Check whether logs match a pattern + * + * The patterns are interpreted as `grep` compatible patterns (BRE regular expressions). If the + * log file does not match the pattern, it is considered an error. + */ + void log_includes(const char* pattern); + + /** + * @brief Check whether logs do not match a pattern + * + * The patterns are interpreted as `grep` compatible patterns (BRE regular expressions). If the + * log file match the pattern, it is considered an error. + */ + void log_excludes(const char* pattern); + /** * @brief FindConnectedSlave Finds slave node which has connections from MaxScale * @param Test TestConnections object which contains info about test setup diff --git a/maxscale-system-test/verify_master_failure.cpp b/maxscale-system-test/verify_master_failure.cpp index 4c961d113..d4614d6ae 100644 --- a/maxscale-system-test/verify_master_failure.cpp +++ b/maxscale-system-test/verify_master_failure.cpp @@ -13,11 +13,12 @@ int main(int argc, char *argv[]) test.tprintf("Blocking master and checking that master failure is delayed at least once."); test.repl->block_node(0); sleep(5); - test.check_log_err("delaying failover", true); + test.log_includes("delaying.*failover"); test.tprintf("Waiting to see if failover is performed."); sleep(10); - test.check_log_err("Performing failover", true); + + test.log_includes("Performing.*failover"); // TODO: Extend the test