Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:add test for redis commands, including LPush, RPushX, BgSave, FlushDb and SetEx #2898

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/integration/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1291,5 +1291,28 @@ var _ = Describe("List Commands", func() {
// Expect(lRange.Err()).NotTo(HaveOccurred())
// Expect(lRange.Val()).To(Equal([]string{"san"}))
//})

It("should lpush and rpushx", func() {
lpush := client.LPush(ctx, "list1", 1, 2, 3, 4)
Expect(lpush.Err()).NotTo(HaveOccurred())
Expect(lpush.Val()).To(Equal(int64(4)))

getRes, err := client.Get(ctx, "list1").Result()
Expect(err).To(HaveOccurred()) // An error is expected since listkey is a list, not a string
Expect(getRes).To(Equal(""))

lrang := client.LRange(ctx, "list1", 0, -1)
Expect(lrang.Err()).NotTo(HaveOccurred())
Expect(lrang.Val()).To(Equal([]string{"4", "3", "2", "1"}))

rpush := client.RPushX(ctx, "list1", 5)
Expect(rpush.Err()).NotTo(HaveOccurred())
Expect(rpush.Val()).To(Equal(int64(5)))

lrang = client.LRange(ctx, "list1", 0, -1)
Expect(lrang.Err()).NotTo(HaveOccurred())
Expect(lrang.Val()).To(Equal([]string{"4", "3", "2", "1", "5"}))

})
})
})
46 changes: 45 additions & 1 deletion tests/integration/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pika_integration
import (
"context"
"time"

"os"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
"github.com/redis/go-redis/v9"
Expand Down Expand Up @@ -161,6 +161,38 @@ var _ = Describe("Server", func() {
Expect(val).To(ContainSubstring("Background append only file rewriting"))
})

It("should BgSave", func() {
res := client.Set(ctx, "bgsava_key1", "bgsava_value1", 0)
Expect(res.Err()).NotTo(HaveOccurred())
_ = client.Set(ctx, "bgsava_key2", "bgsava_value2", 0)
Expect(res.Err()).NotTo(HaveOccurred())

res2, err2 := client.BgSave(ctx).Result()
Expect(err2).NotTo(HaveOccurred())
Expect(res.Err()).NotTo(HaveOccurred())
Expect(res2).To(ContainSubstring("Background saving started"))
dumpPath := "../dump/"

time.Sleep(5 * time.Second)
//wait for bgsave complete

files, err := os.ReadDir(dumpPath)
Expect(err).NotTo(HaveOccurred())
//need to delete test bgsave file?

Expect(len(files)).To(BeNumerically(">", 0), "dump directory is empty, bgsave create file failed")

})

It("should FlushDb", func() {
res := client.Do(ctx, "flushdb")
Expect(res.Err()).NotTo(HaveOccurred())
Expect(res.Val()).To(Equal("OK"))

keys, err := client.Keys(ctx, "*").Result()
Expect(err).NotTo(HaveOccurred())
Expect(keys).To(BeEmpty())
})
// Test scenario: Execute the del command, after executing bgsave, the get data will be wrong
//It("should BgSave", func() {
// res := client.Set(ctx, "bgsava_key", "bgsava_value", 0)
Expand Down Expand Up @@ -446,6 +478,18 @@ var _ = Describe("Server", func() {
Expect(info.Val()).To(ContainSubstring(`used_cpu_sys`))
})

It("should Info after second", func() {
info := client.Info(ctx)
time.Sleep(1 * time.Second)
Expect(info.Err()).NotTo(HaveOccurred())
Expect(info.Val()).NotTo(Equal(""))

info = client.Info(ctx, "all")
time.Sleep(1 * time.Second)
Expect(info.Err()).NotTo(HaveOccurred())
Expect(info.Val()).NotTo(Equal(""))
})

It("should Info cpu", func() {
info := client.Info(ctx, "cpu")
Expect(info.Err()).NotTo(HaveOccurred())
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,25 @@ var _ = Describe("String Commands", func() {
}, "2s", "100ms").Should(Equal(redis.Nil))
})

It("should SetEX ten seconds", func() {
err := client.SetEx(ctx, "x", "y", 10 * time.Second).Err()
Expect(err).NotTo(HaveOccurred())

val, err := client.Get(ctx, "x").Result()
Expect(err).NotTo(HaveOccurred())
Expect(val).To(Equal("y"))

time.Sleep(11 * time.Second)
//sleep 10 second x still exists

err = client.Do(ctx, "compact").Err()
Expect(err).NotTo(HaveOccurred())

keys, err := client.Keys(ctx, "x").Result()
Expect(err).NotTo(HaveOccurred())
Expect(keys).To(BeEmpty())
})

It("should SetNX", func() {
_, err := client.Del(ctx, "key").Result()
Expect(err).NotTo(HaveOccurred())
Expand Down
Loading