@@ -23,11 +23,6 @@ import (
2323 log "github.com/sirupsen/logrus"
2424)
2525
26- const (
27- TestValue = 1234.56
28- TimeToSleep = 200
29- )
30-
3126var (
3227 keys []string
3328 keysExpiring []string
4136)
4237
4338const (
44- TestSetName = "test-set"
45- TestStreamName = "test-stream"
46- TestHllName = "test-hll"
39+ TestKeysSetName = "test-set"
40+ TestKeysStreamName = "test-stream"
41+ TestKeysHllName = "test-hll"
4742)
4843
4944func getTestExporter () * Exporter {
@@ -75,16 +70,17 @@ func setupKeys(t *testing.T, c redis.Conn, dbNumStr string) error {
7570 // not failing on this one - cluster doesn't allow for SELECT so we log and ignore the error
7671 }
7772
73+ testValue := 1234.56
7874 for _ , key := range keys {
79- if _ , err := c .Do ("SET" , key , TestValue ); err != nil {
75+ if _ , err := c .Do ("SET" , key , testValue ); err != nil {
8076 t .Errorf ("couldn't setup redis, err: %s " , err )
8177 return err
8278 }
8379 }
8480
8581 // set to expire in 300 seconds, should be plenty for a test run
8682 for _ , key := range keysExpiring {
87- if _ , err := c .Do ("SETEX" , key , "300" , TestValue ); err != nil {
83+ if _ , err := c .Do ("SETEX" , key , "300" , testValue ); err != nil {
8884 t .Errorf ("couldn't setup redis, err: %s " , err )
8985 return err
9086 }
@@ -99,25 +95,43 @@ func setupKeys(t *testing.T, c redis.Conn, dbNumStr string) error {
9995 }
10096 }
10197
102- c .Do ("PFADD" , TestHllName , "val1" )
103- c .Do ("PFADD" , TestHllName , "val22" )
104- c .Do ("PFADD" , TestHllName , "val333" )
98+ if _ , err := c .Do ("PFADD" , TestKeysHllName , "val1" ); err != nil {
99+ t .Errorf ("PFADD err: %s" , err )
100+ return err
101+ }
102+ if _ , err := c .Do ("PFADD" , TestKeysHllName , "val22" ); err != nil {
103+ t .Errorf ("PFADD err: %s" , err )
104+ return err
105+ }
106+ if _ , err := c .Do ("PFADD" , TestKeysHllName , "val333" ); err != nil {
107+ t .Errorf ("PFADD err: %s" , err )
108+ return err
109+ }
105110
106- c .Do ("SADD" , TestSetName , "test-val-1" )
107- c .Do ("SADD" , TestSetName , "test-val-2" )
111+ if _ , err := c .Do ("SADD" , TestKeysSetName , "test-val-1" ); err != nil {
112+ t .Errorf ("SADD err: %s" , err )
113+ return err
114+ }
115+ if _ , err := c .Do ("SADD" , TestKeysSetName , "test-val-2" ); err != nil {
116+ t .Errorf ("SADD err: %s" , err )
117+ return err
118+ }
108119
109- c .Do ("SET" , singleStringKey , "this-is-a-string" )
120+ if _ , err := c .Do ("SET" , singleStringKey , "this-is-a-string" ); err != nil {
121+ t .Errorf ("PFADD err: %s" , err )
122+ return err
123+ }
110124
111125 // Create test streams
112- c .Do ("XGROUP" , "CREATE" , TestStreamName , "test_group_1" , "$" , "MKSTREAM" )
113- c .Do ("XGROUP" , "CREATE" , TestStreamName , "test_group_2" , "$" , "MKSTREAM" )
114- c .Do ("XADD" , TestStreamName , TestStreamTimestamps [0 ], "field_1" , "str_1" )
115- c .Do ("XADD" , TestStreamName , TestStreamTimestamps [1 ], "field_2" , "str_2" )
126+ c .Do ("XGROUP" , "CREATE" , TestKeysStreamName , "test_group_1" , "$" , "MKSTREAM" )
127+ c .Do ("XGROUP" , "CREATE" , TestKeysStreamName , "test_group_2" , "$" , "MKSTREAM" )
128+ c .Do ("XADD" , TestKeysStreamName , TestStreamTimestamps [0 ], "field_1" , "str_1" )
129+ c .Do ("XADD" , TestKeysStreamName , TestStreamTimestamps [1 ], "field_2" , "str_2" )
116130
117131 // Process messages to assign Consumers to their groups
118- c .Do ("XREADGROUP" , "GROUP" , "test_group_1" , "test_consumer_1" , "COUNT" , "1" , "STREAMS" , TestStreamName , ">" )
119- c .Do ("XREADGROUP" , "GROUP" , "test_group_1" , "test_consumer_2" , "COUNT" , "1" , "STREAMS" , TestStreamName , ">" )
120- c .Do ("XREADGROUP" , "GROUP" , "test_group_2" , "test_consumer_1" , "COUNT" , "1" , "STREAMS" , TestStreamName , "0" )
132+ c .Do ("XREADGROUP" , "GROUP" , "test_group_1" , "test_consumer_1" , "COUNT" , "1" , "STREAMS" , TestKeysStreamName , ">" )
133+ c .Do ("XREADGROUP" , "GROUP" , "test_group_1" , "test_consumer_2" , "COUNT" , "1" , "STREAMS" , TestKeysStreamName , ">" )
134+ c .Do ("XREADGROUP" , "GROUP" , "test_group_2" , "test_consumer_1" , "COUNT" , "1" , "STREAMS" , TestKeysStreamName , "0" )
121135
122136 return nil
123137}
@@ -140,9 +154,9 @@ func deleteKeys(c redis.Conn, dbNumStr string) {
140154 c .Do ("DEL" , key )
141155 }
142156
143- c .Do ("DEL" , TestHllName )
144- c .Do ("DEL" , TestSetName )
145- c .Do ("DEL" , TestStreamName )
157+ c .Do ("DEL" , TestKeysHllName )
158+ c .Do ("DEL" , TestKeysSetName )
159+ c .Do ("DEL" , TestKeysStreamName )
146160 c .Do ("DEL" , singleStringKey )
147161}
148162
@@ -174,8 +188,7 @@ func setupDBKeysCluster(t *testing.T, uri string) error {
174188
175189 defer c .Close ()
176190
177- err = setupKeys (t , c , "0" )
178- if err != nil {
191+ if err = setupKeys (t , c , "0" ); err != nil {
179192 t .Errorf ("couldn't setup redis, err: %s " , err )
180193 return err
181194 }
0 commit comments