diff --git a/src/pika_admin.cc b/src/pika_admin.cc index 57833143ca..1325672b0a 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -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; } diff --git a/tests/integration/server_test.go b/tests/integration/server_test.go index e1059a6199..742c3c80cd 100644 --- a/tests/integration/server_test.go +++ b/tests/integration/server_test.go @@ -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()