Skip to content

Commit

Permalink
Add Travis CI config.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Dec 30, 2013
1 parent 4fbe517 commit be223ae
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 53 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: go

services:
- redis-server

go:
- 1.0
- 1.1
- 1.2
- tip

install:
- go get launchpad.net/gocheck
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
go test ./v2
82 changes: 44 additions & 38 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ func (t *RedisConnectorTest) TestTCPConnector(c *C) {
ping := client.Ping()
c.Check(ping.Err(), IsNil)
c.Check(ping.Val(), Equals, "PONG")
c.Assert(client.Close(), IsNil)
}

func (t *RedisConnectorTest) TestUnixConnector(c *C) {
client := redis.NewUnixClient("/tmp/redis.sock", "", -1)
ping := client.Ping()
c.Check(ping.Err(), IsNil)
c.Check(ping.Val(), Equals, "PONG")
c.Assert(client.Close(), IsNil)
}

//------------------------------------------------------------------------------
Expand All @@ -79,24 +81,26 @@ type RedisConnPoolTest struct {

var _ = Suite(&RedisConnPoolTest{})

func (t *RedisConnPoolTest) SetUpTest(c *C) {
if t.client == nil {
openConn := func() (net.Conn, error) {
t.openedConnCount++
return net.Dial("tcp", redisAddr)
}
initConn := func(c *redis.Client) error {
t.initedConnCount++
return nil
}
closeConn := func(conn net.Conn) error {
t.closedConnCount++
return nil
}

t.client = redis.NewClient(openConn, closeConn, initConn)
t.client.ConnPool.(*redis.MultiConnPool).MaxCap = 10
func (t *RedisConnPoolTest) SetUpSuite(c *C) {
openConn := func() (net.Conn, error) {
t.openedConnCount++
return net.Dial("tcp", redisAddr)
}
initConn := func(c *redis.Client) error {
t.initedConnCount++
return nil
}
closeConn := func(conn net.Conn) error {
t.closedConnCount++
return nil
}

t.client = redis.NewClient(openConn, closeConn, initConn)
t.client.ConnPool.(*redis.MultiConnPool).MaxCap = 10
}

func (t *RedisConnPoolTest) TearDownSuite(c *C) {
c.Assert(t.client.Close(), IsNil)
}

func (t *RedisConnPoolTest) TearDownTest(c *C) {
Expand Down Expand Up @@ -227,24 +231,26 @@ var _ = Suite(&RedisTest{})

func Test(t *testing.T) { TestingT(t) }

func (t *RedisTest) SetUpTest(c *C) {
if t.client == nil {
openConn := func() (net.Conn, error) {
t.openedConnCount++
return net.Dial("tcp", redisAddr)
}
initConn := func(c *redis.Client) error {
t.initedConnCount++
return nil
}
closeConn := func(conn net.Conn) error {
t.closedConnCount++
return nil
}

t.client = redis.NewClient(openConn, closeConn, initConn)
t.client.ConnPool.(*redis.MultiConnPool).MaxCap = 10
func (t *RedisTest) SetUpSuite(c *C) {
openConn := func() (net.Conn, error) {
t.openedConnCount++
return net.Dial("tcp", redisAddr)
}
initConn := func(c *redis.Client) error {
t.initedConnCount++
return nil
}
closeConn := func(conn net.Conn) error {
t.closedConnCount++
return nil
}

t.client = redis.NewClient(openConn, closeConn, initConn)
t.client.ConnPool.(*redis.MultiConnPool).MaxCap = 10
}

func (t *RedisTest) TearDownSuite(c *C) {
c.Assert(t.client.Close(), IsNil)
}

func (t *RedisTest) TearDownTest(c *C) {
Expand Down Expand Up @@ -323,7 +329,7 @@ func (t *RedisTest) TestManyKeys(c *C) {
}
keys := t.client.Keys("keys.*")
c.Assert(keys.Err(), IsNil)
c.Assert(keys.Val(), HasLen, 100000)
c.Assert(len(keys.Val()), Equals, 100000)
}

func (t *RedisTest) TestManyKeys2(c *C) {
Expand All @@ -337,7 +343,7 @@ func (t *RedisTest) TestManyKeys2(c *C) {

mget := t.client.MGet(keys...)
c.Assert(mget.Err(), IsNil)
c.Assert(mget.Val(), HasLen, 100002)
c.Assert(len(mget.Val()), Equals, 100002)
vals := mget.Val()
for i := 0; i < 100000; i++ {
c.Assert(vals[i+1], Equals, "hello"+strconv.Itoa(i))
Expand Down Expand Up @@ -2554,7 +2560,7 @@ func (t *RedisTest) TestPipelineIncrFromGoroutines(c *C) {

reqs, err := pipeline.RunQueued()
c.Assert(err, IsNil)
c.Assert(reqs, HasLen, 20000)
c.Assert(len(reqs), Equals, 20000)
for _, req := range reqs {
if req.Err() != nil {
c.Errorf("got %v, expected nil", req.Err())
Expand Down Expand Up @@ -2691,7 +2697,7 @@ func (t *RedisTest) TestMultiExecIncrTransaction(c *C) {
}
})
c.Assert(err, IsNil)
c.Assert(reqs, HasLen, 20000)
c.Assert(len(reqs), Equals, 20000)
for _, req := range reqs {
if req.Err() != nil {
c.Errorf("got %v, expected nil", req.Err())
Expand Down
38 changes: 23 additions & 15 deletions v2/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,26 @@ type RedisConnectorTest struct{}

var _ = Suite(&RedisConnectorTest{})

func (t *RedisConnectorTest) TestTCPConnector(c *C) {
func (t *RedisConnectorTest) TestNewTCPClient(c *C) {
client := redis.NewTCPClient(&redis.Options{
Addr: ":6379",
})
ping := client.Ping()
c.Check(ping.Err(), IsNil)
c.Check(ping.Val(), Equals, "PONG")
c.Assert(client.Close(), IsNil)
}

func (t *RedisConnectorTest) TestUnixConnector(c *C) {
func (t *RedisConnectorTest) TestNewUnixClient(c *C) {
c.Skip("not available on Travis CI")

client := redis.NewUnixClient(&redis.Options{
Addr: "/tmp/redis.sock",
})
ping := client.Ping()
c.Check(ping.Err(), IsNil)
c.Check(ping.Val(), Equals, "PONG")
c.Assert(client.Close(), IsNil)
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -235,11 +239,11 @@ func (t *RedisTest) SetUpSuite(c *C) {
})
}

func (t *RedisTest) SetUpTest(c *C) {
t.resetRedis(c)
func (t *RedisTest) TearDownSuite(c *C) {
c.Assert(t.client.Close(), IsNil)
}

func (t *RedisTest) TearDownTest(c *C) {
func (t *RedisTest) SetUpTest(c *C) {
t.resetRedis(c)
}

Expand Down Expand Up @@ -307,7 +311,7 @@ func (t *RedisTest) TestManyKeys(c *C) {
}
keys := t.client.Keys("keys.*")
c.Assert(keys.Err(), IsNil)
c.Assert(keys.Val(), HasLen, 100000)
c.Assert(len(keys.Val()), Equals, 100000)
}

func (t *RedisTest) TestManyKeys2(c *C) {
Expand All @@ -321,7 +325,7 @@ func (t *RedisTest) TestManyKeys2(c *C) {

mget := t.client.MGet(keys...)
c.Assert(mget.Err(), IsNil)
c.Assert(mget.Val(), HasLen, 100002)
c.Assert(len(mget.Val()), Equals, 100002)
vals := mget.Val()
for i := 0; i < 100000; i++ {
c.Assert(vals[i+1], Equals, "hello"+strconv.Itoa(i))
Expand Down Expand Up @@ -560,7 +564,8 @@ func (t *RedisTest) TestCmdKeysPExpireAt(c *C) {
c.Assert(set.Err(), IsNil)
c.Assert(set.Val(), Equals, "OK")

pExpireAt := t.client.PExpireAt("key", time.Now().Add(900*time.Millisecond))
expire := 900 * time.Millisecond
pExpireAt := t.client.PExpireAt("key", time.Now().Add(expire))
c.Assert(pExpireAt.Err(), IsNil)
c.Assert(pExpireAt.Val(), Equals, true)

Expand All @@ -570,7 +575,8 @@ func (t *RedisTest) TestCmdKeysPExpireAt(c *C) {

pttl := t.client.PTTL("key")
c.Assert(pttl.Err(), IsNil)
c.Assert(pttl.Val(), Equals, 900*time.Millisecond)
c.Assert(pttl.Val() <= expire, Equals, true)
c.Assert(pttl.Val() >= expire-time.Millisecond, Equals, true)
}

func (t *RedisTest) TestCmdKeysPTTL(c *C) {
Expand Down Expand Up @@ -968,13 +974,15 @@ func (t *RedisTest) TestStringsMSetNX(c *C) {
}

func (t *RedisTest) TestStringsPSetEx(c *C) {
pSetEx := t.client.PSetEx("key", 50*time.Millisecond, "hello")
expire := 50 * time.Millisecond
pSetEx := t.client.PSetEx("key", expire, "hello")
c.Assert(pSetEx.Err(), IsNil)
c.Assert(pSetEx.Val(), Equals, "OK")

pttl := t.client.PTTL("key")
c.Assert(pttl.Err(), IsNil)
c.Assert(pttl.Val(), Equals, 50*time.Millisecond)
c.Assert(pttl.Val() <= expire, Equals, true)
c.Assert(pttl.Val() >= expire-time.Millisecond, Equals, true)

get := t.client.Get("key")
c.Assert(get.Err(), IsNil)
Expand Down Expand Up @@ -2474,7 +2482,7 @@ func (t *RedisTest) TestPipelineIncr(c *C) {

cmds, err := pipeline.Exec()
c.Assert(err, IsNil)
c.Assert(cmds, HasLen, 20000)
c.Assert(len(cmds), Equals, 20000)
for _, cmd := range cmds {
if cmd.Err() != nil {
c.Errorf("got %v, expected nil", cmd.Err())
Expand Down Expand Up @@ -2608,7 +2616,7 @@ func (t *RedisTest) TestMultiExecIncr(c *C) {
}
})
c.Assert(err, IsNil)
c.Assert(cmds, HasLen, 20000)
c.Assert(len(cmds), Equals, 20000)
for _, cmd := range cmds {
if cmd.Err() != nil {
c.Errorf("got %v, expected nil", cmd.Err())
Expand Down Expand Up @@ -2961,8 +2969,8 @@ func (t *RedisTest) BenchmarkRedisGet(c *C) {
func (t *RedisTest) BenchmarkRedisMGet(c *C) {
c.StopTimer()

mSet := t.client.MSet("key1", "hello1", "key2", "hello2")
c.Assert(mSet.Err(), IsNil)
mset := t.client.MSet("key1", "hello1", "key2", "hello2")
c.Assert(mset.Err(), IsNil)

c.StartTimer()

Expand Down

0 comments on commit be223ae

Please sign in to comment.