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