From ba4682c2a34e5667e2096ab897f5692794201fe9 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sat, 18 Jul 2015 11:22:42 +0300 Subject: [PATCH] Fix benchmarks to use Redis on default port and FLUSHDB before run. --- cluster_test.go | 4 ++++ pool_test.go | 6 ++---- redis_test.go | 51 +++++++++++++++++++------------------------------ 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/cluster_test.go b/cluster_test.go index 9173fae..136340c 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -305,6 +305,10 @@ var _ = Describe("Cluster", func() { //------------------------------------------------------------------------------ func BenchmarkRedisClusterPing(b *testing.B) { + if testing.Short() { + b.Skip("skipping in short mode") + } + cluster := &clusterScenario{ ports: []string{"8220", "8221", "8222", "8223", "8224", "8225"}, nodeIds: make([]string, 6), diff --git a/pool_test.go b/pool_test.go index a4fa76e..bff892c 100644 --- a/pool_test.go +++ b/pool_test.go @@ -182,11 +182,9 @@ var _ = Describe("Pool", func() { }) func BenchmarkPool(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: redisAddr, - IdleTimeout: 100 * time.Millisecond, - }) + client := benchRedisClient() defer client.Close() + pool := client.Pool() b.ResetTimer() diff --git a/redis_test.go b/redis_test.go index 3c0d635..1122df9 100644 --- a/redis_test.go +++ b/redis_test.go @@ -169,12 +169,18 @@ var _ = Describe("Client", func() { //------------------------------------------------------------------------------ -const benchRedisAddr = ":6379" +func benchRedisClient() *redis.Client { + client := redis.NewClient(&redis.Options{ + Addr: ":6379", + }) + if err := client.FlushDb().Err(); err != nil { + panic(err) + } + return client +} func BenchmarkRedisPing(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() b.ResetTimer() @@ -189,10 +195,9 @@ func BenchmarkRedisPing(b *testing.B) { } func BenchmarkRedisSet(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() + value := string(bytes.Repeat([]byte{'1'}, 10000)) b.ResetTimer() @@ -207,13 +212,8 @@ func BenchmarkRedisSet(b *testing.B) { } func BenchmarkRedisGetNil(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() - if err := client.FlushDb().Err(); err != nil { - b.Fatal(err) - } b.ResetTimer() @@ -227,9 +227,7 @@ func BenchmarkRedisGetNil(b *testing.B) { } func BenchmarkRedisGet(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() value := bytes.Repeat([]byte{'1'}, 10000) @@ -253,9 +251,7 @@ func BenchmarkRedisGet(b *testing.B) { } func BenchmarkRedisGetSetBytes(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() src := bytes.Repeat([]byte{'1'}, 10000) @@ -280,10 +276,9 @@ func BenchmarkRedisGetSetBytes(b *testing.B) { } func BenchmarkRedisMGet(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() + if err := client.MSet("key1", "hello1", "key2", "hello2").Err(); err != nil { b.Fatal(err) } @@ -300,9 +295,7 @@ func BenchmarkRedisMGet(b *testing.B) { } func BenchmarkSetExpire(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() b.ResetTimer() @@ -320,9 +313,7 @@ func BenchmarkSetExpire(b *testing.B) { } func BenchmarkPipeline(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() b.ResetTimer() @@ -342,9 +333,7 @@ func BenchmarkPipeline(b *testing.B) { } func BenchmarkZAdd(b *testing.B) { - client := redis.NewClient(&redis.Options{ - Addr: benchRedisAddr, - }) + client := benchRedisClient() defer client.Close() b.ResetTimer()