Skip to content

Commit c8c8a3f

Browse files
authored
improve zset testing, fix race condition in test (#50)
1 parent dadcc59 commit c8c8a3f

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export GOFLAGS=-mod=vendor
99
all: test build
1010

1111
test:
12-
go test ./...
12+
go test -race ./...
1313
go vet ./...
1414

1515
build:

pkg/redisdump/redisdump_test.go

+27-1
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ func (m *mockRadixAction) Run(conn radix.Conn) error {
322322
*v = "list"
323323
}
324324
}
325+
if strings.Contains(key, "zset") {
326+
switch v := m.rcv.(type) {
327+
case *string:
328+
*v = "zset"
329+
}
330+
}
325331

326332
return nil
327333
}
@@ -363,7 +369,19 @@ func (m *mockRadixAction) Run(conn radix.Conn) error {
363369
*v = a
364370

365371
default:
366-
fmt.Printf("ERRORRRR")
372+
fmt.Printf("ERROR")
373+
}
374+
return nil
375+
}
376+
377+
if m.cmd == "ZRANGEBYSCORE" {
378+
switch v := m.rcv.(type) {
379+
case *[]string:
380+
a := []string{"listkey1", "1", "listkey2", "2"}
381+
*v = a
382+
383+
default:
384+
fmt.Printf("ERROR")
367385
}
368386
return nil
369387
}
@@ -408,6 +426,11 @@ func TestDumpKeys(t *testing.T) {
408426
true,
409427
"^SET somestring stringvalue\nEXPIREAT somestring [0-9]+\n$",
410428
},
429+
{
430+
[]string{"somezset"},
431+
false,
432+
"^ZADD somezset 1 listkey1 2 listkey2\n$",
433+
},
411434
} {
412435
var m mockRadixClient
413436
var b bytes.Buffer
@@ -449,14 +472,17 @@ func TestScanKeysLegacy(t *testing.T) {
449472
keyBatches := make(chan []string)
450473

451474
n := 0
475+
done := make(chan bool)
452476
go func() {
453477
for b := range keyBatches {
454478
n += len(b)
455479
}
480+
done <- true
456481
}()
457482

458483
err := scanKeysLegacy(&m, getMockRadixAction, 0, 100, "*", keyBatches, nil)
459484
close(keyBatches)
485+
<-done
460486
if err != testCase.err {
461487
t.Errorf("test %d, expected err to be %s, got %s", i, testCase.err, err)
462488
}

0 commit comments

Comments
 (0)