forked from lateefj/slowgrog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_test.go
80 lines (72 loc) · 1.51 KB
/
cmd_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"fmt"
"strings"
"testing"
"time"
"github.com/Sirupsen/logrus"
)
func init() {
Logger.Formatter = new(logrus.TextFormatter)
Logger.Level = logrus.Debug
}
func TestMonitorCmd(t *testing.T) {
rc := NewRedisCmds()
stopper := make(chan bool, 1)
replies := rc.MonitorCmd(stopper)
timeout := time.AfterFunc(1*time.Second, func() {
stopper <- true
t.Fatalf("Failed timout execed reply")
})
// Push a bunch of calls for monitor
for i := 0; i < 100; i++ {
rc.InfoCmd()
}
for r := range replies {
f := strings.Index(r, "INFO")
if f > -1 {
break
}
}
stopper <- true
timeout.Stop()
}
func TestInfoCmd(t *testing.T) {
rc := NewRedisCmds()
s, err := rc.InfoCmd()
if err != nil {
t.Fatalf("Error running InfoCmd %s", err)
}
if strings.Index(s, "redis_version") < 0 {
t.Fatalf("Expected to find 'redis_version' in the InfoCmd")
}
}
func TestSlowlogCmd(t *testing.T) {
rc := NewRedisCmds()
genSize := 100
for x := 0; x < genSize; x++ {
k := fmt.Sprintf("_slowlog_test_%d", x)
rc.conn().Do("SET", k, x)
rc.conn().Do("GET", k, x)
}
rc.conn().Flush()
for x := 0; x < genSize; x++ {
go func() {
rc.conn().Send("KEYS", "*slowlog*")
}()
}
for x := 0; x < genSize; x++ {
k := fmt.Sprintf("_slowlog_test_%d", x)
rc.conn().Send("DEL", k)
}
logs, err := rc.SlowlogCmd()
if err != nil {
t.Fatalf("Failed to call slowlogcmd error: %s", err)
}
if logs == nil {
t.Fatalf("No slowlogs :(")
}
if len(logs) < 1 {
t.Errorf("Expected 10 logs got %d", len(logs))
}
}