Skip to content

Commit

Permalink
improve zset testing, fix race condition in test
Browse files Browse the repository at this point in the history
  • Loading branch information
yannh committed Dec 27, 2023
1 parent dadcc59 commit 4a9902e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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

0 comments on commit 4a9902e

Please sign in to comment.