Skip to content

dfly_bench: Send auth if required before cluster setup #5107

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

Merged
merged 2 commits into from
May 13, 2025
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
19 changes: 15 additions & 4 deletions src/server/dfly_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,21 @@ void KeyGenerator::EnableClusterMode() {
++i;
}
}
void Driver::RunCommandAndCheckResultIs(std::string_view cmd, std::string_view expected_res) {
auto ec = socket_->Write(io::Buffer(cmd));

void RunCommandAndCheckResultIs(std::string_view cmd, std::string_view expected,
FiberSocketBase* socket) {
auto ec = socket->Write(io::Buffer(cmd));
CHECK(!ec);

uint8_t buf[128];
auto res_sz = socket_->Recv(io::MutableBytes(buf));
auto res_sz = socket->Recv(io::MutableBytes(buf));
CHECK(res_sz) << res_sz.error().message();
string_view resp = io::View(io::Bytes(buf, *res_sz));
CHECK_EQ(resp, expected_res) << resp;
CHECK_EQ(resp, expected) << resp;
}

void Driver::RunCommandAndCheckResultIs(std::string_view cmd, std::string_view expected_res) {
::RunCommandAndCheckResultIs(cmd, expected_res, socket_.get());
}

void Driver::Connect(unsigned index, const tcp::endpoint& ep) {
Expand Down Expand Up @@ -1007,6 +1013,11 @@ ClusterShards FetchClusterInfo(const tcp::endpoint& ep, ProactorBase* proactor)
unique_ptr<FiberSocketBase> socket(proactor->CreateSocket());
error_code ec = socket->Connect(ep);
CHECK(!ec) << "Could not connect to " << ep << " " << ec;

if (const auto password = GetFlag(FLAGS_password); !password.empty()) {
RunCommandAndCheckResultIs(StrFormat("AUTH %s\r\n", password), "+OK\r\n", socket.get());
}

ec = socket->Write(io::Buffer("cluster nodes\r\n"));
CHECK(!ec);
facade::RedisParser parser{RedisParser::CLIENT, 1024};
Expand Down
Loading