Skip to content

Commit

Permalink
Merge pull request redis#227 from go-redis/fix/stabilize-build
Browse files Browse the repository at this point in the history
Stabilize build.
  • Loading branch information
vmihailenco committed Dec 22, 2015
2 parents 2be2924 + 36487d8 commit f6d6826
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c *ClusterClient) Close() error {
c.clientsMx.Lock()

if c.closed {
return nil
return errClosed
}
c.closed = true
c.resetClients()
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion cluster_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var _ = Describe("ClusterClient", func() {
})

AfterEach(func() {
subject.Close()
_ = subject.Close()
})

It("should initialize", func() {
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
40 changes: 28 additions & 12 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package redis_test

import (
"errors"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 (
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit f6d6826

Please sign in to comment.