mirror of https://github.com/go-redis/redis.git
Merge pull request #227 from go-redis/fix/stabilize-build
Stabilize build.
This commit is contained in:
commit
f6d6826d82
1
Makefile
1
Makefile
|
@ -1,6 +1,5 @@
|
||||||
all: testdeps
|
all: testdeps
|
||||||
go test ./... -test.v -test.cpu=1,2,4
|
go test ./... -test.v -test.cpu=1,2,4
|
||||||
sleep 3 # give Redis time to exit
|
|
||||||
go test ./... -test.v -test.short -test.race
|
go test ./... -test.v -test.short -test.race
|
||||||
|
|
||||||
testdeps: .test/redis/src/redis-server
|
testdeps: .test/redis/src/redis-server
|
||||||
|
|
10
cluster.go
10
cluster.go
|
@ -64,7 +64,7 @@ func (c *ClusterClient) Close() error {
|
||||||
c.clientsMx.Lock()
|
c.clientsMx.Lock()
|
||||||
|
|
||||||
if c.closed {
|
if c.closed {
|
||||||
return nil
|
return errClosed
|
||||||
}
|
}
|
||||||
c.closed = true
|
c.closed = true
|
||||||
c.resetClients()
|
c.resetClients()
|
||||||
|
@ -197,14 +197,14 @@ func (c *ClusterClient) process(cmd Cmder) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Closes all clients and returns last error if there are any.
|
// 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 {
|
for addr, client := range c.clients {
|
||||||
if e := client.Close(); e != nil {
|
if err := client.Close(); err != nil && retErr == nil {
|
||||||
err = e
|
retErr = err
|
||||||
}
|
}
|
||||||
delete(c.clients, addr)
|
delete(c.clients, addr)
|
||||||
}
|
}
|
||||||
return err
|
return retErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClusterClient) setSlots(slots []ClusterSlotInfo) {
|
func (c *ClusterClient) setSlots(slots []ClusterSlotInfo) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ var _ = Describe("ClusterClient", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
AfterEach(func() {
|
AfterEach(func() {
|
||||||
subject.Close()
|
_ = subject.Close()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should initialize", func() {
|
It("should initialize", func() {
|
||||||
|
|
|
@ -254,7 +254,7 @@ func ExamplePubSub_Receive() {
|
||||||
|
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
// ReceiveTimeout is a low level API. Use ReceiveMessage instead.
|
// 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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
40
main_test.go
40
main_test.go
|
@ -1,6 +1,7 @@
|
||||||
package redis_test
|
package redis_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -130,20 +131,19 @@ func execCmd(name string, args ...string) (*os.Process, error) {
|
||||||
return cmd.Process, cmd.Start()
|
return cmd.Process, cmd.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectTo(port string) (client *redis.Client, err error) {
|
func connectTo(port string) (*redis.Client, error) {
|
||||||
client = redis.NewClient(&redis.Options{
|
client := redis.NewClient(&redis.Options{
|
||||||
Addr: ":" + port,
|
Addr: ":" + port,
|
||||||
})
|
})
|
||||||
|
|
||||||
deadline := time.Now().Add(3 * time.Second)
|
err := eventually(func() error {
|
||||||
for time.Now().Before(deadline) {
|
return client.Ping().Err()
|
||||||
if err = client.Ping().Err(); err == nil {
|
}, 10*time.Second)
|
||||||
return client, nil
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
time.Sleep(250 * time.Millisecond)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, err
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type redisProcess struct {
|
type redisProcess struct {
|
||||||
|
@ -152,8 +152,22 @@ type redisProcess struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *redisProcess) Close() error {
|
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()
|
p.Client.Close()
|
||||||
return p.Kill()
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -165,9 +179,11 @@ func redisDir(port string) (string, error) {
|
||||||
dir, err := filepath.Abs(filepath.Join(".test", "instances", port))
|
dir, err := filepath.Abs(filepath.Join(".test", "instances", port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
} else if err = os.RemoveAll(dir); err != nil {
|
}
|
||||||
|
if err := os.RemoveAll(dir); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
} else if err = os.MkdirAll(dir, 0775); err != nil {
|
}
|
||||||
|
if err := os.MkdirAll(dir, 0775); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return dir, nil
|
return dir, nil
|
||||||
|
|
|
@ -49,7 +49,7 @@ var _ = Describe("Redis ring", func() {
|
||||||
Expect(ringShard2.Info().Val()).To(ContainSubstring("keys=43"))
|
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.
|
// Stop ringShard2.
|
||||||
Expect(ringShard2.Close()).NotTo(HaveOccurred())
|
Expect(ringShard2.Close()).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue