Skip to content

Commit

Permalink
bugfix:slaveof itself (#2170)
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiaoshuai123 committed Nov 27, 2023
1 parent 3b74bce commit dace6b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void SlaveofCmd::DoInitial() {
return;
}

if ((master_ip_ == "127.0.0.1" || master_ip_ == g_pika_server->host()) && master_port_ == g_pika_server->port()) {
if ((pstd::StringToLower(master_ip_) == "localhost" || master_ip_ == "127.0.0.1" || master_ip_ == g_pika_server->host()) && master_port_ == g_pika_server->port()) {
res_.SetRes(CmdRes::kErrOther, "The master ip:port and the slave ip:port are the same");
return;
}
Expand Down
21 changes: 11 additions & 10 deletions tests/integration/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,17 @@ var _ = Describe("Server", func() {
// }, "10s").Should(Equal("OK"))
//})

// todo 待回滚
//It("should SlaveOf", func() {
// slaveOf := client.SlaveOf(ctx, "localhost", "8888")
// Expect(slaveOf.Err()).NotTo(HaveOccurred())
// Expect(slaveOf.Val()).To(Equal("OK"))
//
// slaveOf = client.SlaveOf(ctx, "NO", "ONE")
// Expect(slaveOf.Err()).NotTo(HaveOccurred())
// Expect(slaveOf.Val()).To(Equal("OK"))
//})
// fix: https://github.com/OpenAtomFoundation/pika/issues/2168
It("should SlaveOf itself", func() {
slaveOf := client.SlaveOf(ctx, "127.0.0.1", "9221")
Expect(slaveOf.Err()).To(MatchError("ERR The master ip:port and the slave ip:port are the same"))

slaveOf = client.SlaveOf(ctx, "localhost", "9221")
Expect(slaveOf.Err()).To(MatchError("ERR The master ip:port and the slave ip:port are the same"))

slaveOf = client.SlaveOf(ctx, "loCalHoSt", "9221")
Expect(slaveOf.Err()).To(MatchError("ERR The master ip:port and the slave ip:port are the same"))
})

It("should Time", func() {
tm, err := client.Time(ctx).Result()
Expand Down

0 comments on commit dace6b7

Please sign in to comment.