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

improve zset testing, fix race condition in test #50

Merged
merged 1 commit into from
Dec 27, 2023
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export GOFLAGS=-mod=vendor
all: test build

test:
go test ./...
go test -race ./...
go vet ./...

build:
Expand Down
28 changes: 27 additions & 1 deletion pkg/redisdump/redisdump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ func (m *mockRadixAction) Run(conn radix.Conn) error {
*v = "list"
}
}
if strings.Contains(key, "zset") {
switch v := m.rcv.(type) {
case *string:
*v = "zset"
}
}

return nil
}
Expand Down Expand Up @@ -363,7 +369,19 @@ func (m *mockRadixAction) Run(conn radix.Conn) error {
*v = a

default:
fmt.Printf("ERRORRRR")
fmt.Printf("ERROR")
}
return nil
}

if m.cmd == "ZRANGEBYSCORE" {
switch v := m.rcv.(type) {
case *[]string:
a := []string{"listkey1", "1", "listkey2", "2"}
*v = a

default:
fmt.Printf("ERROR")
}
return nil
}
Expand Down Expand Up @@ -408,6 +426,11 @@ func TestDumpKeys(t *testing.T) {
true,
"^SET somestring stringvalue\nEXPIREAT somestring [0-9]+\n$",
},
{
[]string{"somezset"},
false,
"^ZADD somezset 1 listkey1 2 listkey2\n$",
},
} {
var m mockRadixClient
var b bytes.Buffer
Expand Down Expand Up @@ -449,14 +472,17 @@ func TestScanKeysLegacy(t *testing.T) {
keyBatches := make(chan []string)

n := 0
done := make(chan bool)
go func() {
for b := range keyBatches {
n += len(b)
}
done <- true
}()

err := scanKeysLegacy(&m, getMockRadixAction, 0, 100, "*", keyBatches, nil)
close(keyBatches)
<-done
if err != testCase.err {
t.Errorf("test %d, expected err to be %s, got %s", i, testCase.err, err)
}
Expand Down
Loading