@@ -23,22 +23,25 @@ import (
2323 log "github.com/sirupsen/logrus"
2424)
2525
26- var (
27- keys []string
28- keysExpiring []string
29- listKeys []string
30- singleStringKey string
31-
26+ const (
3227 dbNumStr = "11"
3328 altDBNumStr = "12"
3429 invalidDBNumStr = "16"
35- dbNumStrFull = fmt .Sprintf ("db%s" , dbNumStr )
3630)
3731
38- const (
39- TestKeysSetName = "test-set"
40- TestKeysStreamName = "test-stream"
41- TestKeysHllName = "test-hll"
32+ var (
33+ keys []string
34+ keysExpiring []string
35+ listKeys []string
36+
37+ dbNumStrFull = fmt .Sprintf ("db%s" , dbNumStr )
38+ )
39+
40+ var (
41+ TestKeyNameSingleString = "" // initialized with a timestamp at runtime
42+ TestKeyNameSet = "test-set"
43+ TestKeyNameStream = "test-stream"
44+ TestKeyNameHll = "test-hll"
4245)
4346
4447func getTestExporter () * Exporter {
@@ -95,43 +98,43 @@ func setupKeys(t *testing.T, c redis.Conn, dbNumStr string) error {
9598 }
9699 }
97100
98- if _ , err := c .Do ("PFADD" , TestKeysHllName , "val1" ); err != nil {
101+ if _ , err := c .Do ("PFADD" , TestKeyNameHll , "val1" ); err != nil {
99102 t .Errorf ("PFADD err: %s" , err )
100103 return err
101104 }
102- if _ , err := c .Do ("PFADD" , TestKeysHllName , "val22" ); err != nil {
105+ if _ , err := c .Do ("PFADD" , TestKeyNameHll , "val22" ); err != nil {
103106 t .Errorf ("PFADD err: %s" , err )
104107 return err
105108 }
106- if _ , err := c .Do ("PFADD" , TestKeysHllName , "val333" ); err != nil {
109+ if _ , err := c .Do ("PFADD" , TestKeyNameHll , "val333" ); err != nil {
107110 t .Errorf ("PFADD err: %s" , err )
108111 return err
109112 }
110113
111- if _ , err := c .Do ("SADD" , TestKeysSetName , "test-val-1" ); err != nil {
114+ if _ , err := c .Do ("SADD" , TestKeyNameSet , "test-val-1" ); err != nil {
112115 t .Errorf ("SADD err: %s" , err )
113116 return err
114117 }
115- if _ , err := c .Do ("SADD" , TestKeysSetName , "test-val-2" ); err != nil {
118+ if _ , err := c .Do ("SADD" , TestKeyNameSet , "test-val-2" ); err != nil {
116119 t .Errorf ("SADD err: %s" , err )
117120 return err
118121 }
119122
120- if _ , err := c .Do ("SET" , singleStringKey , "this-is-a-string" ); err != nil {
123+ if _ , err := c .Do ("SET" , TestKeyNameSingleString , "this-is-a-string" ); err != nil {
121124 t .Errorf ("PFADD err: %s" , err )
122125 return err
123126 }
124127
125128 // Create test streams
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" )
129+ c .Do ("XGROUP" , "CREATE" , TestKeyNameStream , "test_group_1" , "$" , "MKSTREAM" )
130+ c .Do ("XGROUP" , "CREATE" , TestKeyNameStream , "test_group_2" , "$" , "MKSTREAM" )
131+ c .Do ("XADD" , TestKeyNameStream , TestStreamTimestamps [0 ], "field_1" , "str_1" )
132+ c .Do ("XADD" , TestKeyNameStream , TestStreamTimestamps [1 ], "field_2" , "str_2" )
130133
131134 // Process messages to assign Consumers to their groups
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" )
135+ c .Do ("XREADGROUP" , "GROUP" , "test_group_1" , "test_consumer_1" , "COUNT" , "1" , "STREAMS" , TestKeyNameStream , ">" )
136+ c .Do ("XREADGROUP" , "GROUP" , "test_group_1" , "test_consumer_2" , "COUNT" , "1" , "STREAMS" , TestKeyNameStream , ">" )
137+ c .Do ("XREADGROUP" , "GROUP" , "test_group_2" , "test_consumer_1" , "COUNT" , "1" , "STREAMS" , TestKeyNameStream , "0" )
135138
136139 time .Sleep (time .Millisecond * 100 )
137140 return nil
@@ -155,10 +158,10 @@ func deleteKeys(c redis.Conn, dbNumStr string) {
155158 c .Do ("DEL" , key )
156159 }
157160
158- c .Do ("DEL" , TestKeysHllName )
159- c .Do ("DEL" , TestKeysSetName )
160- c .Do ("DEL" , TestKeysStreamName )
161- c .Do ("DEL" , singleStringKey )
161+ c .Do ("DEL" , TestKeyNameHll )
162+ c .Do ("DEL" , TestKeyNameSet )
163+ c .Do ("DEL" , TestKeyNameStream )
164+ c .Do ("DEL" , TestKeyNameSingleString )
162165}
163166
164167func setupDBKeys (t * testing.T , uri string ) {
@@ -363,15 +366,9 @@ func TestKeysReset(t *testing.T) {
363366 setupDBKeys (t , os .Getenv ("TEST_REDIS_URI" ))
364367 defer deleteKeysFromDB (t , os .Getenv ("TEST_REDIS_URI" ))
365368
366- chM := make (chan prometheus.Metric , 10000 )
367- go func () {
368- e .Collect (chM )
369- close (chM )
370- }()
371-
372369 body := downloadURL (t , ts .URL + "/metrics" )
373370 if ! strings .Contains (body , keys [0 ]) {
374- t .Errorf ("Did not found key %q\n %s" , keys [0 ], body )
371+ t .Errorf ("Did not find key %q\n %s" , keys [0 ], body )
375372 }
376373
377374 deleteKeysFromDB (t , os .Getenv ("TEST_REDIS_URI" ))
@@ -468,7 +465,7 @@ func init() {
468465 keys = append (keys , fmt .Sprintf ("key_%s_%d" , n , testTimestamp ))
469466 }
470467
471- singleStringKey = fmt .Sprintf ("key_string_%d" , testTimestamp )
468+ TestKeyNameSingleString = fmt .Sprintf ("key_string_%d" , testTimestamp )
472469
473470 listKeys = append (listKeys , "beatles_list" )
474471
0 commit comments