From 4cc4deeaf157a80030c96c607b1fe1fb5a5b3312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Sun, 13 May 2018 21:25:16 +0300 Subject: [PATCH] MXS-1843: Test log throtting in a unique directory This rules out external influence as a reason for the test failure. --- server/core/test/testlogthrottling.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/server/core/test/testlogthrottling.cc b/server/core/test/testlogthrottling.cc index 685d8ea7b..12db4cfbb 100644 --- a/server/core/test/testlogthrottling.cc +++ b/server/core/test/testlogthrottling.cc @@ -34,7 +34,8 @@ using std::string; namespace { -const char LOGNAME[] = "/tmp/maxscale.log"; +const char LOGNAME[] = "maxscale.log"; +static string logfile; const size_t N_THREADS = 4; sem_t u_semstart; @@ -109,7 +110,7 @@ bool run(const MXS_LOG_THROTTLING& throttling, int priority, size_t n_generate, mxs_log_set_throttling(&throttling); // Causes message to be logged. mxs_log_flush_sync(); - ifstream in(LOGNAME); + ifstream in(logfile); in.seekg(0, ios_base::end); THREAD_ARG args[N_THREADS]; @@ -166,9 +167,13 @@ int main(int argc, char* argv[]) rc = sem_init(&u_semfinish, 0, 0); ensure(rc == 0); - unlink(LOGNAME); - if (mxs_log_init(NULL, "/tmp", MXS_LOG_TARGET_FS)) + char tmpbuf[] = "/tmp/maxscale_test_logthrottling_XXXXXX"; + char* logdir = mkdtemp(tmpbuf); + ensure(logdir); + logfile.assign(string{logdir} + '/' + LOGNAME); + + if (mxs_log_init(NULL, logdir, MXS_LOG_TARGET_FS)) { MXS_LOG_THROTTLING t; @@ -265,5 +270,10 @@ int main(int argc, char* argv[]) rc = EXIT_FAILURE; } + // A crude method to remove all files but it works + string cmd = "rm -r "; + cmd += logdir; + system(cmd.c_str()); + return rc; }