Merge pull request #227 from go-redis/fix/stabilize-build

Stabilize build.
This commit is contained in:
Vladimir Mihailenco 2015-12-22 12:21:49 +02:00
commit f6d6826d82
6 changed files with 36 additions and 21 deletions

View File

@ -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

View File

@ -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) {

View File

@ -37,7 +37,7 @@ var _ = Describe("ClusterClient", func() {
})
AfterEach(func() {
subject.Close()
_ = subject.Close()
})
It("should initialize", func() {

View File

@ -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)
}

View File

@ -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

View File

@ -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())