1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00

fix(cluster): Reply with correct \n / \r\n from CLUSTER sub cmd (#2731)

* fix(cluster): Reply with correct `\n` / `\r\n` from `CLUSTER` sub commands

Fixes #2726

* fix tests
This commit is contained in:
Shahar Mike 2024-03-17 10:23:46 +02:00 committed by GitHub
parent 8e38d24fe2
commit e9548a2917
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 9 deletions

View file

@ -250,7 +250,8 @@ void ClusterNodesImpl(const ClusterShards& config, string_view my_id, Connection
} }
} }
absl::StrAppend(&result, "\r\n"); // Separate lines with only \n, not \r\n, see #2726
absl::StrAppend(&result, "\n");
}; };
for (const auto& shard : config) { for (const auto& shard : config) {
@ -280,6 +281,7 @@ namespace {
void ClusterInfoImpl(const ClusterShards& config, ConnectionContext* cntx) { void ClusterInfoImpl(const ClusterShards& config, ConnectionContext* cntx) {
std::string msg; std::string msg;
auto append = [&msg](absl::AlphaNum a1, absl::AlphaNum a2) { auto append = [&msg](absl::AlphaNum a1, absl::AlphaNum a2) {
// Separate lines with \r\n, not \n, see #2726
absl::StrAppend(&msg, a1, ":", a2, "\r\n"); absl::StrAppend(&msg, a1, ":", a2, "\r\n");
}; };

View file

@ -188,7 +188,7 @@ TEST_F(ClusterFamilyTest, ClusterConfigNoReplicas) {
"abcd1234"))))); "abcd1234")))));
EXPECT_EQ(Run({"cluster", "nodes"}), EXPECT_EQ(Run({"cluster", "nodes"}),
"abcd1234 10.0.0.1:7000@7000 master - 0 0 0 connected 0-16383\r\n"); "abcd1234 10.0.0.1:7000@7000 master - 0 0 0 connected 0-16383\n");
} }
TEST_F(ClusterFamilyTest, ClusterConfigFull) { TEST_F(ClusterFamilyTest, ClusterConfigFull) {
@ -259,8 +259,8 @@ TEST_F(ClusterFamilyTest, ClusterConfigFull) {
"wxyz"))))); "wxyz")))));
EXPECT_EQ(Run({"cluster", "nodes"}), EXPECT_EQ(Run({"cluster", "nodes"}),
"abcd1234 10.0.0.1:7000@7000 master - 0 0 0 connected 0-16383\r\n" "abcd1234 10.0.0.1:7000@7000 master - 0 0 0 connected 0-16383\n"
"wxyz 10.0.0.10:8000@8000 slave abcd1234 0 0 0 connected\r\n"); "wxyz 10.0.0.10:8000@8000 slave abcd1234 0 0 0 connected\n");
} }
TEST_F(ClusterFamilyTest, ClusterConfigFullMultipleInstances) { TEST_F(ClusterFamilyTest, ClusterConfigFullMultipleInstances) {
@ -383,10 +383,10 @@ TEST_F(ClusterFamilyTest, ClusterConfigFullMultipleInstances) {
"qwerty"))))))); "qwerty")))))));
EXPECT_THAT(Run({"cluster", "nodes"}), EXPECT_THAT(Run({"cluster", "nodes"}),
"abcd1234 10.0.0.1:7000@7000 master - 0 0 0 connected 0-10000\r\n" "abcd1234 10.0.0.1:7000@7000 master - 0 0 0 connected 0-10000\n"
"wxyz 10.0.0.10:8000@8000 slave abcd1234 0 0 0 connected\r\n" "wxyz 10.0.0.10:8000@8000 slave abcd1234 0 0 0 connected\n"
"efgh7890 10.0.0.2:7001@7001 master - 0 0 0 connected 10001-16383\r\n" "efgh7890 10.0.0.2:7001@7001 master - 0 0 0 connected 10001-16383\n"
"qwerty 10.0.0.11:8001@8001 slave efgh7890 0 0 0 connected\r\n"); "qwerty 10.0.0.11:8001@8001 slave efgh7890 0 0 0 connected\n");
absl::InsecureBitGen eng; absl::InsecureBitGen eng;
while (true) { while (true) {
@ -818,7 +818,7 @@ TEST_F(ClusterFamilyEmulatedTest, ClusterSlots) {
TEST_F(ClusterFamilyEmulatedTest, ClusterNodes) { TEST_F(ClusterFamilyEmulatedTest, ClusterNodes) {
EXPECT_THAT(Run({"cluster", "nodes"}), EXPECT_THAT(Run({"cluster", "nodes"}),
GetMyId() + " fake-host:6379@6379 myself,master - 0 0 0 connected 0-16383\r\n"); GetMyId() + " fake-host:6379@6379 myself,master - 0 0 0 connected 0-16383\n");
} }
} // namespace } // namespace