1
0
mirror of https://github.com/redis/go-redis.git synced 2025-08-01 16:06:54 +03:00

Fix race in tests.

This commit is contained in:
Vladimir Mihailenco
2016-04-09 11:34:40 +03:00
parent b351402995
commit 787609d1e6
3 changed files with 9 additions and 8 deletions

View File

@ -8,8 +8,6 @@ import (
"gopkg.in/redis.v3/internal/pool"
)
var receiveMessageTimeout = 5 * time.Second
// Posts a message to the given channel.
func (c *Client) Publish(channel, message string) *IntCmd {
req := NewIntCmd("PUBLISH", channel, message)
@ -255,9 +253,13 @@ func (c *PubSub) Receive() (interface{}, error) {
// messages. It automatically reconnects to Redis Server and resubscribes
// to channels in case of network errors.
func (c *PubSub) ReceiveMessage() (*Message, error) {
return c.receiveMessage(5 * time.Second)
}
func (c *PubSub) receiveMessage(timeout time.Duration) (*Message, error) {
var errNum uint
for {
msgi, err := c.ReceiveTimeout(receiveMessageTimeout)
msgi, err := c.ReceiveTimeout(timeout)
if err != nil {
if !isNetworkError(err) {
return nil, err