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

fix: add rename go test #2468

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 15 additions & 0 deletions tests/conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,18 @@ cache-lfu-decay-time: 1
#
# aclfile : ../conf/users.acl

# It is possible to change the name of dangerous commands in a shared environment.
# For instance the CONFIG command may be renamed into something Warning: To prevent
# data inconsistency caused by different configuration files, do not use the rename
# command to modify write commands on the primary and secondary servers. If necessary,
# ensure that the configuration files of the primary and secondary servers are consistent
# In addition, when using the command rename, you must not use "" to modify the command,
# for example, rename-command: FLUSHALL "360flushall" is incorrect; instead, use
# rename-command: FLUSHALL 360flushall is correct. After the rename command is executed,
# it is most appropriate to use a numeric string with uppercase or lowercase letters
# for example: rename-command : FLUSHALL joYAPNXRPmcarcR4ZDgC81TbdkSmLAzRPmcarcR
#
# Example:
#
# rename-command : FLUSHALL 360flushall
# rename-command : FLUSHDB 360flushdb
1 change: 1 addition & 0 deletions tests/integration/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
SINGLEADDR = "127.0.0.1:9221"
SLAVEADDR = "127.0.0.1:9231"
MASTERADDR = "127.0.0.1:9241"
RenameADDR = "127.0.0.1:9251"
)

type TimeValue struct {
Expand Down
62 changes: 62 additions & 0 deletions tests/integration/renamecommand_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package pika_integration

import (
"context"
"time"

. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
"github.com/redis/go-redis/v9"
)

var _ = Describe("Rename Command test", func() {
ctx := context.TODO()
var client *redis.Client

BeforeEach(func() {
client = redis.NewClient(PikaOption(RenameADDR))
time.Sleep(1 * time.Second)
})

AfterEach(func() {
Expect(client.Close()).NotTo(HaveOccurred())
})

It("should 360FlushDB", func() {
set := client.Set(ctx, "key", "foobar", 0)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK"))

bitCount := client.BitCount(ctx, "key", nil)
Expect(bitCount.Err()).NotTo(HaveOccurred())
Expect(bitCount.Val()).To(Equal(int64(26)))
_, err := client.Do(ctx, "360flushdb").Result()
Expect(err).NotTo(HaveOccurred())
r := client.Do(ctx, "360flushdb")
Expect(r.Val()).To(Equal("OK"))
n, err := client.Exists(ctx, "key").Result()
Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(int64(0)))
r = client.Do(ctx, "flushdb")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果执行 flushdb,那应该返回错误,因为你把 flushdb 命令重命名了?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

返回错误和结果不是OK是不是逻辑一样,NotTo(Equal("OK"))

Expect(r.Val()).NotTo(Equal("OK"))
})

It("should 360FlushAll", func() {
set := client.Set(ctx, "key", "foobar", 0)
Expect(set.Err()).NotTo(HaveOccurred())
Expect(set.Val()).To(Equal("OK"))

bitCount := client.BitCount(ctx, "key", nil)
Expect(bitCount.Err()).NotTo(HaveOccurred())
Expect(bitCount.Val()).To(Equal(int64(26)))
_, err := client.Do(ctx, "360flushall").Result()
Expect(err).NotTo(HaveOccurred())
r := client.Do(ctx, "360flushall")
Expect(r.Val()).To(Equal("OK"))
n, err := client.Exists(ctx, "key").Result()
Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(int64(0)))
r = client.Do(ctx, "flushall")
Expect(r.Val()).NotTo(Equal("OK"))
})
})
3 changes: 3 additions & 0 deletions tests/integration/start_master_and_slave.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ cp ../../output/pika ./pika
cp ../conf/pika.conf ./pika_single.conf
cp ../conf/pika.conf ./pika_master.conf
cp ../conf/pika.conf ./pika_slave.conf
cp ../conf/pika.conf ./pika_rename.conf
# Create folders for storing data on the primary and secondary nodes
mkdir master_data
mkdir slave_data
# Example Change the location for storing data on primary and secondary nodes in the configuration file
sed -i '' -e 's|databases : 1|databases : 2|' -e 's|#daemonize : yes|daemonize : yes|' ./pika_single.conf
sed -i '' -e 's|databases : 1|databases : 2|' -e 's|port : 9221|port : 9241|' -e 's|log-path : ./log/|log-path : ./master_data/log/|' -e 's|db-path : ./db/|db-path : ./master_data/db/|' -e 's|dump-path : ./dump/|dump-path : ./master_data/dump/|' -e 's|pidfile : ./pika.pid|pidfile : ./master_data/pika.pid|' -e 's|db-sync-path : ./dbsync/|db-sync-path : ./master_data/dbsync/|' -e 's|#daemonize : yes|daemonize : yes|' ./pika_master.conf
sed -i '' -e 's|databases : 1|databases : 2|' -e 's|port : 9221|port : 9231|' -e 's|log-path : ./log/|log-path : ./slave_data/log/|' -e 's|db-path : ./db/|db-path : ./slave_data/db/|' -e 's|dump-path : ./dump/|dump-path : ./slave_data/dump/|' -e 's|pidfile : ./pika.pid|pidfile : ./slave_data/pika.pid|' -e 's|db-sync-path : ./dbsync/|db-sync-path : ./slave_data/dbsync/|' -e 's|#daemonize : yes|daemonize : yes|' ./pika_slave.conf
sed -i '' -e 's|# rename-command : FLUSHALL 360flushall|rename-command : FLUSHALL 360flushall|' -e 's|# rename-command : FLUSHDB 360flushdb|rename-command : FLUSHDB 360flushdb|' -e 's|databases : 1|databases : 2|' -e 's|port : 9221|port : 9251|' -e 's|log-path : ./log/|log-path : ./rename_data/log/|' -e 's|db-path : ./db/|db-path : ./rename_data/db/|' -e 's|dump-path : ./dump/|dump-path : ./rename_data/dump/|' -e 's|pidfile : ./pika.pid|pidfile : ./rename_data/pika.pid|' -e 's|db-sync-path : ./dbsync/|db-sync-path : ./rename_data/dbsync/|' -e 's|#daemonize : yes|daemonize : yes|' ./pika_rename.conf
# Start three nodes
./pika -c ./pika_single.conf
./pika -c ./pika_master.conf
./pika -c ./pika_slave.conf
./pika -c ./pika_rename.conf
#ensure both master and slave are ready
sleep 10
Loading