make util.Until return immediately if stop is written inside the loop

This commit is contained in:
Mike Danese
2015-11-04 16:31:02 -08:00
parent f64780d6eb
commit 8b9809291b
2 changed files with 23 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ import (
"reflect"
"strings"
"testing"
"time"
"github.com/ghodss/yaml"
)
@@ -48,6 +49,17 @@ func TestUntil(t *testing.T) {
<-called
}
func TestUntilReturnsImmediately(t *testing.T) {
now := time.Now()
ch := make(chan struct{})
Until(func() {
close(ch)
}, 30*time.Second, ch)
if now.Add(25 * time.Second).Before(time.Now()) {
t.Errorf("Until did not return immediately when the stop chan was closed inside the func")
}
}
func TestHandleCrash(t *testing.T) {
count := 0
expect := 10