mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #3644 from mitake/test-race
etcdserver, test: don't access testing.T in time.AfterFunc()'s own go…
This commit is contained in:
commit
f74ff9b867
@ -604,11 +604,18 @@ func TestSync(t *testing.T) {
|
|||||||
reqIDGen: idutil.NewGenerator(0, time.Time{}),
|
reqIDGen: idutil.NewGenerator(0, time.Time{}),
|
||||||
}
|
}
|
||||||
// check that sync is non-blocking
|
// check that sync is non-blocking
|
||||||
timer := time.AfterFunc(time.Second, func() {
|
done := make(chan struct{})
|
||||||
t.Fatalf("sync should be non-blocking but did not return after 1s!")
|
go func() {
|
||||||
})
|
|
||||||
srv.sync(10 * time.Second)
|
srv.sync(10 * time.Second)
|
||||||
timer.Stop()
|
done <- struct{}{}
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
t.Fatal("sync should be non-blocking but did not return after 1s!")
|
||||||
|
}
|
||||||
|
|
||||||
testutil.WaitSchedule()
|
testutil.WaitSchedule()
|
||||||
|
|
||||||
action := n.Action()
|
action := n.Action()
|
||||||
@ -637,11 +644,17 @@ func TestSyncTimeout(t *testing.T) {
|
|||||||
reqIDGen: idutil.NewGenerator(0, time.Time{}),
|
reqIDGen: idutil.NewGenerator(0, time.Time{}),
|
||||||
}
|
}
|
||||||
// check that sync is non-blocking
|
// check that sync is non-blocking
|
||||||
timer := time.AfterFunc(time.Second, func() {
|
done := make(chan struct{})
|
||||||
t.Fatalf("sync should be non-blocking but did not return after 1s!")
|
go func() {
|
||||||
})
|
|
||||||
srv.sync(0)
|
srv.sync(0)
|
||||||
timer.Stop()
|
done <- struct{}{}
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
t.Fatal("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
|
||||||
testutil.WaitSchedule()
|
testutil.WaitSchedule()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user