From 36487d84626d74a6600ee7a06017b7e6d9fa1187 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Tue, 22 Dec 2015 11:44:49 +0200 Subject: [PATCH] Stabilize build. --- Makefile | 1 - cluster.go | 10 +++++----- cluster_client_test.go | 2 +- example_test.go | 2 +- main_test.go | 40 ++++++++++++++++++++++++++++------------ ring_test.go | 2 +- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index bda28e35..e9fdd93b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ all: testdeps go test ./... -test.v -test.cpu=1,2,4 - sleep 3 # give Redis time to exit go test ./... -test.v -test.short -test.race testdeps: .test/redis/src/redis-server diff --git a/cluster.go b/cluster.go index 43bfc8df..418844e7 100644 --- a/cluster.go +++ b/cluster.go @@ -64,7 +64,7 @@ func (c *ClusterClient) Close() error { c.clientsMx.Lock() if c.closed { - return nil + return errClosed } c.closed = true c.resetClients() @@ -197,14 +197,14 @@ func (c *ClusterClient) process(cmd Cmder) { } // Closes all clients and returns last error if there are any. -func (c *ClusterClient) resetClients() (err error) { +func (c *ClusterClient) resetClients() (retErr error) { for addr, client := range c.clients { - if e := client.Close(); e != nil { - err = e + if err := client.Close(); err != nil && retErr == nil { + retErr = err } delete(c.clients, addr) } - return err + return retErr } func (c *ClusterClient) setSlots(slots []ClusterSlotInfo) { diff --git a/cluster_client_test.go b/cluster_client_test.go index c7f695d4..9502ba05 100644 --- a/cluster_client_test.go +++ b/cluster_client_test.go @@ -37,7 +37,7 @@ var _ = Describe("ClusterClient", func() { }) AfterEach(func() { - subject.Close() + _ = subject.Close() }) It("should initialize", func() { diff --git a/example_test.go b/example_test.go index ff992562..bb98fdd5 100644 --- a/example_test.go +++ b/example_test.go @@ -254,7 +254,7 @@ func ExamplePubSub_Receive() { for i := 0; i < 2; i++ { // ReceiveTimeout is a low level API. Use ReceiveMessage instead. - msgi, err := pubsub.ReceiveTimeout(100 * time.Millisecond) + msgi, err := pubsub.ReceiveTimeout(500 * time.Millisecond) if err != nil { panic(err) } diff --git a/main_test.go b/main_test.go index 806d7d3d..471c8ee9 100644 --- a/main_test.go +++ b/main_test.go @@ -1,6 +1,7 @@ package redis_test import ( + "errors" "net" "os" "os/exec" @@ -130,20 +131,19 @@ func execCmd(name string, args ...string) (*os.Process, error) { return cmd.Process, cmd.Start() } -func connectTo(port string) (client *redis.Client, err error) { - client = redis.NewClient(&redis.Options{ +func connectTo(port string) (*redis.Client, error) { + client := redis.NewClient(&redis.Options{ Addr: ":" + port, }) - deadline := time.Now().Add(3 * time.Second) - for time.Now().Before(deadline) { - if err = client.Ping().Err(); err == nil { - return client, nil - } - time.Sleep(250 * time.Millisecond) + err := eventually(func() error { + return client.Ping().Err() + }, 10*time.Second) + if err != nil { + return nil, err } - return nil, err + return client, nil } type redisProcess struct { @@ -152,8 +152,22 @@ type redisProcess struct { } func (p *redisProcess) Close() error { + if err := p.Kill(); err != nil { + return err + } + + err := eventually(func() error { + if err := p.Client.Ping().Err(); err != nil { + return nil + } + return errors.New("client is not shutdown") + }, 10*time.Second) + if err != nil { + return err + } + p.Client.Close() - return p.Kill() + return nil } var ( @@ -165,9 +179,11 @@ func redisDir(port string) (string, error) { dir, err := filepath.Abs(filepath.Join(".test", "instances", port)) if err != nil { return "", err - } else if err = os.RemoveAll(dir); err != nil { + } + if err := os.RemoveAll(dir); err != nil { return "", err - } else if err = os.MkdirAll(dir, 0775); err != nil { + } + if err := os.MkdirAll(dir, 0775); err != nil { return "", err } return dir, nil diff --git a/ring_test.go b/ring_test.go index 0de37dc4..7d5cd91c 100644 --- a/ring_test.go +++ b/ring_test.go @@ -49,7 +49,7 @@ var _ = Describe("Redis ring", func() { Expect(ringShard2.Info().Val()).To(ContainSubstring("keys=43")) }) - It("uses one shard when other shard is down", func() { + It("uses single shard when one of the shards is down", func() { // Stop ringShard2. Expect(ringShard2.Close()).NotTo(HaveOccurred())