From 301d2f13531f85cfe8286f6be70c4a1f34317337 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Tue, 17 Sep 2013 12:03:17 +0300 Subject: [PATCH] v2: Add defensive pool check. --- v2/pool.go | 4 ++++ v2/redis_test.go | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/v2/pool.go b/v2/pool.go index 2b3ba0d..4be1f1a 100644 --- a/v2/pool.go +++ b/v2/pool.go @@ -117,6 +117,10 @@ func (p *connPool) Get() (*conn, bool, error) { } func (p *connPool) Put(cn *conn) error { + if cn.Rd.Buffered() != 0 { + panic("pool: put connection with buffered data") + } + p.cond.L.Lock() cn.UsedAt = time.Now() p.conns.PushFront(cn) diff --git a/v2/redis_test.go b/v2/redis_test.go index 836e0b6..81f83ce 100644 --- a/v2/redis_test.go +++ b/v2/redis_test.go @@ -27,19 +27,25 @@ func sortStrings(slice []string) []string { //------------------------------------------------------------------------------ -type RedisShutdownTest struct { +type RedisConnectionTest struct { + opt *redis.Options client *redis.Client } -var _ = Suite(&RedisShutdownTest{}) +var _ = Suite(&RedisConnectionTest{}) -func (t *RedisShutdownTest) SetUpTest(c *C) { - t.client = redis.DialTCP(&redis.Options{ +func (t *RedisConnectionTest) SetUpTest(c *C) { + t.opt = &redis.Options{ Addr: redisAddr, - }) + } + t.client = redis.DialTCP(t.opt) } -func (t *RedisShutdownTest) TestShutdown(c *C) { +func (t *RedisConnectionTest) TearDownTest(c *C) { + c.Assert(t.client.Close(), IsNil) +} + +func (t *RedisConnectionTest) TestShutdown(c *C) { c.Skip("shutdowns server") shutdown := t.client.Shutdown()