Merge pull request #1505 from yichengq/193

etcdserver: refactor non-blocking check for sync tests
This commit is contained in:
Yicheng Qin 2014-11-06 15:48:18 -08:00
commit ccded6644a

View File

@ -698,12 +698,17 @@ func TestSync(t *testing.T) {
srv := &EtcdServer{ srv := &EtcdServer{
node: n, node: n,
} }
start := time.Now() done := make(chan struct{})
srv.sync(defaultSyncTimeout) go func() {
srv.sync(10 * time.Second)
close(done)
}()
// check that sync is non-blocking // check that sync is non-blocking
if d := time.Since(start); d > time.Millisecond { select {
t.Errorf("CallSyncTime = %v, want < %v", d, time.Millisecond) case <-done:
case <-time.After(time.Second):
t.Fatalf("sync should be non-blocking but did not return after 1s!")
} }
testutil.ForceGosched() testutil.ForceGosched()
@ -727,12 +732,17 @@ func TestSyncTimeout(t *testing.T) {
srv := &EtcdServer{ srv := &EtcdServer{
node: n, node: n,
} }
start := time.Now() done := make(chan struct{})
srv.sync(0) go func() {
srv.sync(0)
close(done)
}()
// check that sync is non-blocking // check that sync is non-blocking
if d := time.Since(start); d > time.Millisecond { select {
t.Errorf("CallSyncTime = %v, want < %v", d, time.Millisecond) case <-done:
case <-time.After(time.Second):
t.Fatalf("sync should be non-blocking but did not return after 1s!")
} }
// give time for goroutine in sync to cancel // give time for goroutine in sync to cancel