Skip to content

Commit 07a928f

Browse files
committed
Fix test with SYSTEM FLUSH LOGS;
On some systems in CI/CD we don't have enough privileges to flush logs and have to wait for this to occur automatically.
1 parent f810c16 commit 07a928f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ut/client_ut.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#include <clickhouse/client.h>
2+
23
#include "readonly_client_test.h"
34
#include "connection_failed_client_test.h"
45
#include "utils.h"
6+
57
#include <gtest/gtest.h>
68

79
#include <cmath>
10+
#include <thread>
11+
#include <chrono>
812

913
using namespace clickhouse;
1014

@@ -882,7 +886,19 @@ TEST_P(ClientCase, Query_ID) {
882886
client_->SelectCancelable("SELECT 'b', count(*) FROM " + table_name, query_id, [](const Block &) { return true; });
883887
client_->Execute(Query("TRUNCATE TABLE " + table_name, query_id));
884888

885-
client_->Execute("SYSTEM FLUSH LOGS");
889+
try {
890+
client_->Execute("SYSTEM FLUSH LOGS");
891+
} catch (const std::exception & e) {
892+
// DB::Exception: clickhouse_cpp_cicd: Not enough privileges. To execute this query it's necessary to have grant SYSTEM FLUSH LOGS ON
893+
if (std::string(e.what()).find("To execute this query it's necessary to have grant SYSTEM FLUSH LOGS ON") != std::string::npos) {
894+
// Insufficient privileges, the only safe way is to wait long enough for system
895+
// to flush the logs automaticaly. Usualy it takes 7.5 seconds, so just in case,
896+
// wait 3 times that to ensure that all previously executed queries are in the logs now.
897+
const auto wait_duration = std::chrono::seconds(23);
898+
std::cerr << "Got error while flushing logs, now we wait " << wait_duration << "..." << std::endl;
899+
std::this_thread::sleep_for(wait_duration);
900+
}
901+
}
886902

887903
size_t total_count = 0;
888904
client_->Select("SELECT type, query_kind, query_id, query "

ut/utils.h

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ inline const char * getPrefix() {
5858
prefix = "c";
5959
} else if constexpr (std::ratio_equal_v<R, std::deci>) {
6060
prefix = "d";
61+
} else if constexpr (std::ratio_equal_v<R, std::ratio<1, 1>>) {
62+
prefix = "";
6163
} else {
6264
static_assert("Unsupported ratio");
6365
}

0 commit comments

Comments
 (0)