@@ -23,22 +23,25 @@ import (
23
23
log "github.com/sirupsen/logrus"
24
24
)
25
25
26
- var (
27
- keys []string
28
- keysExpiring []string
29
- listKeys []string
30
- singleStringKey string
31
-
26
+ const (
32
27
dbNumStr = "11"
33
28
altDBNumStr = "12"
34
29
invalidDBNumStr = "16"
35
- dbNumStrFull = fmt .Sprintf ("db%s" , dbNumStr )
36
30
)
37
31
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"
42
45
)
43
46
44
47
func getTestExporter () * Exporter {
@@ -95,43 +98,43 @@ func setupKeys(t *testing.T, c redis.Conn, dbNumStr string) error {
95
98
}
96
99
}
97
100
98
- if _ , err := c .Do ("PFADD" , TestKeysHllName , "val1" ); err != nil {
101
+ if _ , err := c .Do ("PFADD" , TestKeyNameHll , "val1" ); err != nil {
99
102
t .Errorf ("PFADD err: %s" , err )
100
103
return err
101
104
}
102
- if _ , err := c .Do ("PFADD" , TestKeysHllName , "val22" ); err != nil {
105
+ if _ , err := c .Do ("PFADD" , TestKeyNameHll , "val22" ); err != nil {
103
106
t .Errorf ("PFADD err: %s" , err )
104
107
return err
105
108
}
106
- if _ , err := c .Do ("PFADD" , TestKeysHllName , "val333" ); err != nil {
109
+ if _ , err := c .Do ("PFADD" , TestKeyNameHll , "val333" ); err != nil {
107
110
t .Errorf ("PFADD err: %s" , err )
108
111
return err
109
112
}
110
113
111
- if _ , err := c .Do ("SADD" , TestKeysSetName , "test-val-1" ); err != nil {
114
+ if _ , err := c .Do ("SADD" , TestKeyNameSet , "test-val-1" ); err != nil {
112
115
t .Errorf ("SADD err: %s" , err )
113
116
return err
114
117
}
115
- if _ , err := c .Do ("SADD" , TestKeysSetName , "test-val-2" ); err != nil {
118
+ if _ , err := c .Do ("SADD" , TestKeyNameSet , "test-val-2" ); err != nil {
116
119
t .Errorf ("SADD err: %s" , err )
117
120
return err
118
121
}
119
122
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 {
121
124
t .Errorf ("PFADD err: %s" , err )
122
125
return err
123
126
}
124
127
125
128
// 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" )
130
133
131
134
// 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" )
135
138
136
139
time .Sleep (time .Millisecond * 100 )
137
140
return nil
@@ -155,10 +158,10 @@ func deleteKeys(c redis.Conn, dbNumStr string) {
155
158
c .Do ("DEL" , key )
156
159
}
157
160
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 )
162
165
}
163
166
164
167
func setupDBKeys (t * testing.T , uri string ) {
@@ -363,15 +366,9 @@ func TestKeysReset(t *testing.T) {
363
366
setupDBKeys (t , os .Getenv ("TEST_REDIS_URI" ))
364
367
defer deleteKeysFromDB (t , os .Getenv ("TEST_REDIS_URI" ))
365
368
366
- chM := make (chan prometheus.Metric , 10000 )
367
- go func () {
368
- e .Collect (chM )
369
- close (chM )
370
- }()
371
-
372
369
body := downloadURL (t , ts .URL + "/metrics" )
373
370
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 )
375
372
}
376
373
377
374
deleteKeysFromDB (t , os .Getenv ("TEST_REDIS_URI" ))
@@ -468,7 +465,7 @@ func init() {
468
465
keys = append (keys , fmt .Sprintf ("key_%s_%d" , n , testTimestamp ))
469
466
}
470
467
471
- singleStringKey = fmt .Sprintf ("key_string_%d" , testTimestamp )
468
+ TestKeyNameSingleString = fmt .Sprintf ("key_string_%d" , testTimestamp )
472
469
473
470
listKeys = append (listKeys , "beatles_list" )
474
471
0 commit comments