Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix unstable unittests. #8344

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions dbms/src/TestUtils/FunctionTestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down