From 8879e3ae1549c63b88a39c57891b940c48dc0798 Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Mon, 15 Apr 2024 16:20:17 +0300 Subject: [PATCH 1/6] Added test case for CLIENT KILL with MAXAGE option --- commands_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/commands_test.go b/commands_test.go index d30a9d8bb..a0186ceaa 100644 --- a/commands_test.go +++ b/commands_test.go @@ -193,6 +193,19 @@ var _ = Describe("Commands", func() { Expect(r.Val()).To(Equal(int64(0))) }) + It("should ClientKillByFilter with MAXAGE", func() { + var s []string + ch := make(chan []string, 1) + go func() { + r1 := client.BLPop(ctx, 10, "list") + ch <- r1.Val() + }() + time.Sleep(200 * time.Millisecond) + r2 := client.ClientKillByFilter(ctx, "MAXAGE", "1") + Expect(r2.Val()).To(Equal(int64(1))) + Expect(<-ch).To(Equal(s)) + }) + It("should ClientID", func() { err := client.ClientID(ctx).Err() Expect(err).NotTo(HaveOccurred()) From 9d683aa1696b16f9184bd6a8def8d338dca2c634 Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Mon, 15 Apr 2024 16:27:36 +0300 Subject: [PATCH 2/6] Fixed sleep value --- commands_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands_test.go b/commands_test.go index a0186ceaa..819aa7beb 100644 --- a/commands_test.go +++ b/commands_test.go @@ -200,7 +200,7 @@ var _ = Describe("Commands", func() { r1 := client.BLPop(ctx, 10, "list") ch <- r1.Val() }() - time.Sleep(200 * time.Millisecond) + time.Sleep(2000 * time.Millisecond) r2 := client.ClientKillByFilter(ctx, "MAXAGE", "1") Expect(r2.Val()).To(Equal(int64(1))) Expect(<-ch).To(Equal(s)) From 6659cf0f7d57e97aedeaeb40783e5586d9520e5c Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Tue, 16 Apr 2024 10:53:24 +0300 Subject: [PATCH 3/6] Added additional condition to kill specific connection --- commands_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/commands_test.go b/commands_test.go index 819aa7beb..6f37b9228 100644 --- a/commands_test.go +++ b/commands_test.go @@ -195,15 +195,16 @@ var _ = Describe("Commands", func() { It("should ClientKillByFilter with MAXAGE", func() { var s []string - ch := make(chan []string, 1) + id := client.ClientID(ctx).Val() go func() { - r1 := client.BLPop(ctx, 10, "list") - ch <- r1.Val() + defer GinkgoRecover() + + r1 := client.BLPop(ctx, 0, "list") + Expect(r1.Val()).To(Equal(s)) }() time.Sleep(2000 * time.Millisecond) - r2 := client.ClientKillByFilter(ctx, "MAXAGE", "1") + r2 := client.ClientKillByFilter(ctx, "MAXAGE", "1", "ID", strconv.FormatInt(id, 10)) Expect(r2.Val()).To(Equal(int64(1))) - Expect(<-ch).To(Equal(s)) }) It("should ClientID", func() { From 2c71300c77603c554ebd5445b06a7cfe83b694f3 Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Tue, 16 Apr 2024 15:07:15 +0300 Subject: [PATCH 4/6] Test commit --- commands_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands_test.go b/commands_test.go index 6f37b9228..45d99e4a4 100644 --- a/commands_test.go +++ b/commands_test.go @@ -195,15 +195,15 @@ var _ = Describe("Commands", func() { It("should ClientKillByFilter with MAXAGE", func() { var s []string - id := client.ClientID(ctx).Val() go func() { defer GinkgoRecover() r1 := client.BLPop(ctx, 0, "list") Expect(r1.Val()).To(Equal(s)) }() + fmt.Println(client.ClientList(ctx).Val()) time.Sleep(2000 * time.Millisecond) - r2 := client.ClientKillByFilter(ctx, "MAXAGE", "1", "ID", strconv.FormatInt(id, 10)) + r2 := client.ClientKillByFilter(ctx, "MAXAGE", "1") Expect(r2.Val()).To(Equal(int64(1))) }) From 4397053e32ea7d5cfc06304ea93f65de4849b362 Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Tue, 16 Apr 2024 15:16:10 +0300 Subject: [PATCH 5/6] Test commit --- commands_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commands_test.go b/commands_test.go index 45d99e4a4..f59b74662 100644 --- a/commands_test.go +++ b/commands_test.go @@ -198,10 +198,11 @@ var _ = Describe("Commands", func() { go func() { defer GinkgoRecover() + fmt.Println("Started") r1 := client.BLPop(ctx, 0, "list") + fmt.Println("Finished") Expect(r1.Val()).To(Equal(s)) }() - fmt.Println(client.ClientList(ctx).Val()) time.Sleep(2000 * time.Millisecond) r2 := client.ClientKillByFilter(ctx, "MAXAGE", "1") Expect(r2.Val()).To(Equal(int64(1))) From 7784beb5422b6652c87c57bd0321587acdb3aba3 Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Tue, 16 Apr 2024 16:44:30 +0300 Subject: [PATCH 6/6] Updated test case to handle timeouts --- commands_test.go | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/commands_test.go b/commands_test.go index f59b74662..ed59eeb16 100644 --- a/commands_test.go +++ b/commands_test.go @@ -195,17 +195,36 @@ var _ = Describe("Commands", func() { It("should ClientKillByFilter with MAXAGE", func() { var s []string + started := make(chan bool) + done := make(chan bool) + go func() { defer GinkgoRecover() - fmt.Println("Started") - r1 := client.BLPop(ctx, 0, "list") - fmt.Println("Finished") - Expect(r1.Val()).To(Equal(s)) + started <- true + blpop := client.BLPop(ctx, 0, "list") + Expect(blpop.Val()).To(Equal(s)) + done <- true }() - time.Sleep(2000 * time.Millisecond) - r2 := client.ClientKillByFilter(ctx, "MAXAGE", "1") - Expect(r2.Val()).To(Equal(int64(1))) + <-started + + select { + case <-done: + Fail("BLPOP is not blocked.") + case <-time.After(2 * time.Second): + // ok + } + + killed := client.ClientKillByFilter(ctx, "MAXAGE", "1") + Expect(killed.Err()).NotTo(HaveOccurred()) + Expect(killed.Val()).To(Equal(int64(2))) + + select { + case <-done: + // ok + case <-time.After(time.Second): + Fail("BLPOP is still blocked.") + } }) It("should ClientID", func() {