1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00

Set read/write timeouts more consistently.

This commit is contained in:
Vladimir Mihailenco
2016-12-03 17:30:13 +02:00
parent e7f23a300b
commit b4efc45f1c
18 changed files with 343 additions and 198 deletions

View File

@ -2,6 +2,7 @@ package redis_test
import (
"errors"
"fmt"
"net"
"os"
"os/exec"
@ -159,8 +160,7 @@ func perform(n int, cbs ...func(int)) {
func eventually(fn func() error, timeout time.Duration) error {
var exit int32
var retErr error
var mu sync.Mutex
errCh := make(chan error)
done := make(chan struct{})
go func() {
@ -172,9 +172,10 @@ func eventually(fn func() error, timeout time.Duration) error {
close(done)
return
}
mu.Lock()
retErr = err
mu.Unlock()
select {
case errCh <- err:
default:
}
time.Sleep(timeout / 100)
}
}()
@ -184,10 +185,12 @@ func eventually(fn func() error, timeout time.Duration) error {
return nil
case <-time.After(timeout):
atomic.StoreInt32(&exit, 1)
mu.Lock()
err := retErr
mu.Unlock()
return err
select {
case err := <-errCh:
return err
default:
return fmt.Errorf("timeout after %s", timeout)
}
}
}