mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1505 from yichengq/193
etcdserver: refactor non-blocking check for sync tests
This commit is contained in:
commit
ccded6644a
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user