From 20c738a1035d83af2362078981d8c1056d3fb401 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Tue, 18 Nov 2014 12:11:06 +0200 Subject: [PATCH] Enable race tests. --- Makefile | 1 + rate_limit_test.go | 7 +++++-- redis_test.go | 16 ++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 6d6d4276..b250d9bf 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,3 @@ all: go test gopkg.in/redis.v2 -cpu=1,2,4 + go test gopkg.in/redis.v2 -short -race diff --git a/rate_limit_test.go b/rate_limit_test.go index f6a47210..2f0d41a2 100644 --- a/rate_limit_test.go +++ b/rate_limit_test.go @@ -7,8 +7,11 @@ import ( ) func TestRateLimiter(t *testing.T) { - const n = 100000 - rl := newRateLimiter(time.Second, n) + var n = 100000 + if testing.Short() { + n = 1000 + } + rl := newRateLimiter(time.Minute, n) wg := &sync.WaitGroup{} for i := 0; i < n; i++ { diff --git a/redis_test.go b/redis_test.go index 55479811..4ce3eb27 100644 --- a/redis_test.go +++ b/redis_test.go @@ -392,17 +392,21 @@ func (t *RedisTest) TestGetBigVal(c *C) { } func (t *RedisTest) TestManyKeys(c *C) { - for i := 0; i < 100000; i++ { + var n = 100000 + + for i := 0; i < n; i++ { t.client.Set("keys.key"+strconv.Itoa(i), "hello"+strconv.Itoa(i)) } keys := t.client.Keys("keys.*") c.Assert(keys.Err(), IsNil) - c.Assert(len(keys.Val()), Equals, 100000) + c.Assert(len(keys.Val()), Equals, n) } func (t *RedisTest) TestManyKeys2(c *C) { + var n = 100000 + keys := []string{"non-existent-key"} - for i := 0; i < 100000; i++ { + for i := 0; i < n; i++ { key := "keys.key" + strconv.Itoa(i) t.client.Set(key, "hello"+strconv.Itoa(i)) keys = append(keys, key) @@ -411,13 +415,13 @@ func (t *RedisTest) TestManyKeys2(c *C) { mget := t.client.MGet(keys...) c.Assert(mget.Err(), IsNil) - c.Assert(len(mget.Val()), Equals, 100002) + c.Assert(len(mget.Val()), Equals, n+2) vals := mget.Val() - for i := 0; i < 100000; i++ { + for i := 0; i < n; i++ { c.Assert(vals[i+1], Equals, "hello"+strconv.Itoa(i)) } c.Assert(vals[0], Equals, nil) - c.Assert(vals[100001], Equals, nil) + c.Assert(vals[n+1], Equals, nil) } func (t *RedisTest) TestStringCmdHelpers(c *C) {