From 80656e83df334de983621dc7ea4ca4155b0e46f0 Mon Sep 17 00:00:00 2001 From: JayLiu <38887641+luky116@users.noreply.github.com> Date: Fri, 8 Mar 2024 21:49:35 +0800 Subject: [PATCH] Integration tests differentiate between cached and non-cached (#2467) Co-authored-by: liuyuecai --- tests/integration/csanning_test.go | 1 + tests/integration/geo_test.go | 1 + tests/integration/hash_test.go | 1 + tests/integration/hyperloglog_test.go | 1 + tests/integration/main_test.go | 29 ++++++++++++++++++++++----- tests/integration/pubsub_test.go | 2 ++ tests/integration/replication_test.go | 2 ++ tests/integration/set_test.go | 1 + tests/integration/slowlog_test.go | 1 + tests/integration/stream_test.go | 1 + tests/integration/string_test.go | 1 + tests/integration/txn_test.go | 3 +++ tests/integration/zset_test.go | 1 + 13 files changed, 40 insertions(+), 5 deletions(-) diff --git a/tests/integration/csanning_test.go b/tests/integration/csanning_test.go index 67bc89f739..dfe3ac8f4d 100644 --- a/tests/integration/csanning_test.go +++ b/tests/integration/csanning_test.go @@ -17,6 +17,7 @@ var _ = Describe("Csanning Commands", func() { BeforeEach(func() { client = redis.NewClient(PikaOption(SINGLEADDR)) Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred()) + GlobalBefore(ctx, client) time.Sleep(1 * time.Second) }) diff --git a/tests/integration/geo_test.go b/tests/integration/geo_test.go index 7b5a4e62b3..86b7c54e84 100644 --- a/tests/integration/geo_test.go +++ b/tests/integration/geo_test.go @@ -16,6 +16,7 @@ var _ = Describe("Geo Commands", func() { BeforeEach(func() { client = redis.NewClient(PikaOption(SINGLEADDR)) Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred()) + GlobalBefore(ctx, client) time.Sleep(1 * time.Second) }) diff --git a/tests/integration/hash_test.go b/tests/integration/hash_test.go index b7938d733b..e4252c523b 100644 --- a/tests/integration/hash_test.go +++ b/tests/integration/hash_test.go @@ -18,6 +18,7 @@ var _ = Describe("Hash Commands", func() { BeforeEach(func() { client = redis.NewClient(PikaOption(SINGLEADDR)) Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred()) + GlobalBefore(ctx, client) time.Sleep(1 * time.Second) }) diff --git a/tests/integration/hyperloglog_test.go b/tests/integration/hyperloglog_test.go index 59d86e69d7..97943766a3 100644 --- a/tests/integration/hyperloglog_test.go +++ b/tests/integration/hyperloglog_test.go @@ -16,6 +16,7 @@ var _ = Describe("Hyperloglog Commands", func() { BeforeEach(func() { client = redis.NewClient(PikaOption(SINGLEADDR)) Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred()) + GlobalBefore(ctx, client) time.Sleep(1 * time.Second) }) diff --git a/tests/integration/main_test.go b/tests/integration/main_test.go index f48bef9637..c64d68cb11 100644 --- a/tests/integration/main_test.go +++ b/tests/integration/main_test.go @@ -1,14 +1,33 @@ package pika_integration import ( - "testing" - + "context" . "github.com/bsm/ginkgo/v2" - . "github.com/bsm/gomega" + "github.com/redis/go-redis/v9" + "testing" ) -func TestPika(t *testing.T) { +var ( + GlobalBefore func(ctx context.Context, client *redis.Client) +) + +func TestPikaWithCache(t *testing.T) { + GlobalBefore = func(ctx context.Context, client *redis.Client) { + Expect(client.SlaveOf(ctx, "NO", "ONE").Err()).NotTo(HaveOccurred()) + Expect(client.FlushAll(ctx).Err()).NotTo(HaveOccurred()) + Expect(client.ConfigSet(ctx, "cache-model", "1").Err()).NotTo(HaveOccurred()) + } + RegisterFailHandler(Fail) + RunSpecs(t, "Pika integration test with cache done") +} + +func TestPikaWithoutCache(t *testing.T) { + GlobalBefore = func(ctx context.Context, client *redis.Client) { + Expect(client.SlaveOf(ctx, "NO", "ONE").Err()).NotTo(HaveOccurred()) + Expect(client.FlushAll(ctx).Err()).NotTo(HaveOccurred()) + Expect(client.ConfigSet(ctx, "cache-model", "0").Err()).NotTo(HaveOccurred()) + } RegisterFailHandler(Fail) - RunSpecs(t, "Pika integration test") + RunSpecs(t, "Pika integration test without cache done") } diff --git a/tests/integration/pubsub_test.go b/tests/integration/pubsub_test.go index 560188ea77..a06317b74f 100644 --- a/tests/integration/pubsub_test.go +++ b/tests/integration/pubsub_test.go @@ -25,6 +25,8 @@ var _ = Describe("PubSub", func() { client2 = redis.NewClient(PikaOption(SINGLEADDR)) Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred()) Expect(client2.FlushDB(ctx).Err()).NotTo(HaveOccurred()) + GlobalBefore(ctx, client) + GlobalBefore(ctx, client2) time.Sleep(2 * time.Second) }) diff --git a/tests/integration/replication_test.go b/tests/integration/replication_test.go index 98dfba89b0..6cd82085a7 100644 --- a/tests/integration/replication_test.go +++ b/tests/integration/replication_test.go @@ -376,6 +376,8 @@ var _ = Describe("should replication ", func() { cleanEnv(ctx, clientMaster, clientSlave) Expect(clientSlave.FlushDB(ctx).Err()).NotTo(HaveOccurred()) Expect(clientMaster.FlushDB(ctx).Err()).NotTo(HaveOccurred()) + GlobalBefore(ctx, clientMaster) + GlobalBefore(ctx, clientSlave) time.Sleep(3 * time.Second) }) AfterEach(func() { diff --git a/tests/integration/set_test.go b/tests/integration/set_test.go index dfe39408fb..2a96beca73 100644 --- a/tests/integration/set_test.go +++ b/tests/integration/set_test.go @@ -16,6 +16,7 @@ var _ = Describe("Set Commands", func() { BeforeEach(func() { client = redis.NewClient(PikaOption(SINGLEADDR)) Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred()) + GlobalBefore(ctx, client) time.Sleep(1 * time.Second) }) diff --git a/tests/integration/slowlog_test.go b/tests/integration/slowlog_test.go index cdb00cd2b4..8d0fddc522 100644 --- a/tests/integration/slowlog_test.go +++ b/tests/integration/slowlog_test.go @@ -20,6 +20,7 @@ var _ = Describe("Slowlog Commands", func() { BeforeEach(func() { client = redis.NewClient(PikaOption(SINGLEADDR)) Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred()) + GlobalBefore(ctx, client) time.Sleep(1 * time.Second) }) diff --git a/tests/integration/stream_test.go b/tests/integration/stream_test.go index 00016e14aa..85b5baa72e 100644 --- a/tests/integration/stream_test.go +++ b/tests/integration/stream_test.go @@ -122,6 +122,7 @@ var _ = Describe("Stream Commands", func() { var client *redis.Client client = redis.NewClient(PikaOption(SINGLEADDR)) client.FlushDB(ctx) + GlobalBefore(ctx, client) BeforeEach(func() { // client = redis.NewClient(pikaOptions1()) diff --git a/tests/integration/string_test.go b/tests/integration/string_test.go index fed216d5a2..25a3243746 100644 --- a/tests/integration/string_test.go +++ b/tests/integration/string_test.go @@ -18,6 +18,7 @@ var _ = Describe("String Commands", func() { BeforeEach(func() { client = redis.NewClient(PikaOption(SINGLEADDR)) Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred()) + GlobalBefore(ctx, client) time.Sleep(1 * time.Second) }) diff --git a/tests/integration/txn_test.go b/tests/integration/txn_test.go index 450c235a74..2f7388f5bc 100644 --- a/tests/integration/txn_test.go +++ b/tests/integration/txn_test.go @@ -30,6 +30,9 @@ var _ = Describe("Text Txn", func() { BeforeEach(func() { txnClient = redis.NewClient(PikaOption(SINGLEADDR)) cmdClient = redis.NewClient(PikaOption(SINGLEADDR)) + + GlobalBefore(ctx, txnClient) + GlobalBefore(ctx, cmdClient) }) Describe("test watch", func() { It("basic watch", func() { diff --git a/tests/integration/zset_test.go b/tests/integration/zset_test.go index abd9fb35b9..7cb9924c2e 100644 --- a/tests/integration/zset_test.go +++ b/tests/integration/zset_test.go @@ -17,6 +17,7 @@ var _ = Describe("Zset Commands", func() { BeforeEach(func() { client = redis.NewClient(PikaOption(SINGLEADDR)) Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred()) + GlobalBefore(ctx, client) time.Sleep(1 * time.Second) })