From b092db0b8f0bede1867b3cebfececad619adfdb7 Mon Sep 17 00:00:00 2001 From: jinhelin Date: Thu, 9 Nov 2023 19:42:43 +0800 Subject: [PATCH] Try to fix unstable unittests. (#8344) ref pingcap/tiflash#6233 --- dbms/src/TestUtils/FunctionTestUtils.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dbms/src/TestUtils/FunctionTestUtils.cpp b/dbms/src/TestUtils/FunctionTestUtils.cpp index 17b85aa887d..5f345c0d306 100644 --- a/dbms/src/TestUtils/FunctionTestUtils.cpp +++ b/dbms/src/TestUtils/FunctionTestUtils.cpp @@ -342,10 +342,13 @@ ColumnWithTypeAndName executeFunction( for (size_t i = 0; i < columns.size(); ++i) argument_column_numbers.push_back(i); + /// Replace `std::random_device` with `std::chrono::system_clock` here to avoid + /// exceptions like 'random_device failed to open /dev/urandom: Operation not permitted'. + /// The reason of exceptions is unknown, but the probability of its occurrence in unittests + /// TestDateTimeDayMonthYear.dayMonthYearTest is not low. + /// Since this function is just used for testing, using current timestamp as a random seed is not a problem. + std::mt19937 g(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())); /// shuffle input columns to assure function correctly use physical offsets instead of logical offsets - std::random_device rd; - std::mt19937 g(rd()); - std::shuffle(argument_column_numbers.begin(), argument_column_numbers.end(), g); const auto columns_reordered = toColumnsReordered(columns, argument_column_numbers);