-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis6_integration_test.go
170 lines (143 loc) · 3.98 KB
/
redis6_integration_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//go:build integration
// Copyright The ActForGood Authors.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://github.com/actforgood/xcache/blob/main/LICENSE.
package xcache_test
import (
"context"
"os"
"strings"
"testing"
"github.com/actforgood/xcache"
"github.com/actforgood/xlog"
)
var redis6ConfigIntegration = xcache.RedisConfig{}
func init() {
redisAddrs := os.Getenv("XCACHE_REDIS6_ADDRS")
redisMasterName := os.Getenv("XCACHE_REDIS6_MASTER_NAME")
if redisAddrs != "" {
addrs := strings.Split(redisAddrs, ",")
redis6ConfigIntegration.Addrs = addrs
}
if redisMasterName != "" {
redis6ConfigIntegration.MasterName = redisMasterName
}
// set the xlog.Logger Redis adapter
loggerOpts := xlog.NewCommonOpts()
loggerOpts.MinLevel = xlog.FixedLevelProvider(xlog.LevelInfo)
loggerOpts.Source = xlog.SourceProvider(5, 1)
logger := xlog.NewSyncLogger(os.Stdout, xlog.SyncLoggerWithOptions(loggerOpts))
redisLogger := xcache.NewRedisXLogger(logger)
xcache.SetRedis6Logger(redisLogger)
}
func TestRedis6_integration(t *testing.T) {
t.Parallel()
// setup
subject := xcache.NewRedis6(redis6ConfigIntegration)
t.Run("wait", func(t *testing.T) { // wait for parallel tests to complete
t.Run("key that does not expire", testCacheWithNoExpireKey(subject))
t.Run("key expires", testCacheWithExpireKey(subject))
t.Run("key does not exist", testCacheWithNotExistKey(subject))
t.Run("delete key", testCacheDeleteKey(subject))
t.Run("ttl for not yet expired key", testCacheTTLWithNotYetExpiredKey(subject))
t.Run("stats", testCacheStats(subject, 256, 1024*1024, ">=", !redis6ConfigIntegration.IsCluster()))
})
// tear down
err := subject.Close()
assertNil(t, err)
}
func BenchmarkRedis6_Save_integration(b *testing.B) {
cache := xcache.NewRedis6(redis6ConfigIntegration)
benchSaveSequential(cache)(b)
b.StopTimer()
stats, err := cache.Stats(context.Background())
if err != nil {
b.Error(err)
}
b.Log(stats)
if err := cache.Close(); err != nil {
b.Error(err)
}
}
func BenchmarkRedis6_Save_parallel_integration(b *testing.B) {
cache := xcache.NewRedis6(redis6ConfigIntegration)
benchSaveParallel(cache)(b)
b.StopTimer()
stats, err := cache.Stats(context.Background())
if err != nil {
b.Error(err)
}
b.Log(stats)
if err := cache.Close(); err != nil {
b.Error(err)
}
}
func BenchmarkRedis6_Load_integration(b *testing.B) {
cache := xcache.NewRedis6(redis6ConfigIntegration)
benchLoadSequential(cache)(b)
b.StopTimer()
stats, err := cache.Stats(context.Background())
if err != nil {
b.Error(err)
}
b.Log(stats)
if err := cache.Close(); err != nil {
b.Error(err)
}
}
func BenchmarkRedis6_Load_parallel_integration(b *testing.B) {
cache := xcache.NewRedis6(redis6ConfigIntegration)
benchLoadParallel(cache)(b)
b.StopTimer()
stats, err := cache.Stats(context.Background())
if err != nil {
b.Error(err)
}
b.Log(stats)
if err := cache.Close(); err != nil {
b.Error(err)
}
}
func BenchmarkRedis6_TTL_integration(b *testing.B) {
cache := xcache.NewRedis6(redis6ConfigIntegration)
benchTTLSequential(cache)(b)
b.StopTimer()
stats, err := cache.Stats(context.Background())
if err != nil {
b.Error(err)
}
b.Log(stats)
if err := cache.Close(); err != nil {
b.Error(err)
}
}
func BenchmarkRedis6_TTL_parallel_integration(b *testing.B) {
cache := xcache.NewRedis6(redis6ConfigIntegration)
benchTTLParallel(cache)(b)
b.StopTimer()
stats, err := cache.Stats(context.Background())
if err != nil {
b.Error(err)
}
b.Log(stats)
if err := cache.Close(); err != nil {
b.Error(err)
}
}
func BenchmarkRedis6_Stats(b *testing.B) {
cache := xcache.NewRedis6(redis6ConfigIntegration)
benchStatsSequential(cache)(b)
b.StopTimer()
if err := cache.Close(); err != nil {
b.Error(err)
}
}
func BenchmarkRedis6_Stats_parallel(b *testing.B) {
cache := xcache.NewRedis6(redis6ConfigIntegration)
benchStatsParallel(cache)(b)
b.StopTimer()
if err := cache.Close(); err != nil {
b.Error(err)
}
}