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

cluster: optimize newClusterState

This commit is contained in:
Vladimir Mihailenco
2018-07-22 10:50:26 +03:00
parent 493945402e
commit 2559f32464
6 changed files with 109 additions and 61 deletions

View File

@ -8,7 +8,6 @@ import (
"os/exec"
"path/filepath"
"sync"
"sync/atomic"
"testing"
"time"
@ -169,24 +168,28 @@ func perform(n int, cbs ...func(int)) {
}
func eventually(fn func() error, timeout time.Duration) error {
var exit int32
errCh := make(chan error)
done := make(chan struct{})
exit := make(chan struct{})
go func() {
defer GinkgoRecover()
for atomic.LoadInt32(&exit) == 0 {
for {
err := fn()
if err == nil {
close(done)
return
}
select {
case errCh <- err:
default:
}
time.Sleep(timeout / 100)
select {
case <-exit:
return
case <-time.After(timeout / 100):
}
}
}()
@ -194,7 +197,7 @@ func eventually(fn func() error, timeout time.Duration) error {
case <-done:
return nil
case <-time.After(timeout):
atomic.StoreInt32(&exit, 1)
close(exit)
select {
case err := <-errCh:
return err