prefer tickers to time.Sleep (Refs #790)

This commit is contained in:
Anton Kaliaev
2017-11-07 15:02:42 -05:00
parent ec87c740a7
commit 2d4ad02356
4 changed files with 84 additions and 83 deletions

View File

@ -20,19 +20,23 @@ func TestNodeStartStop(t *testing.T) {
n.Start()
t.Logf("Started node %v", n.sw.NodeInfo())
// Wait a bit to initialize
// TODO remove time.Sleep(), make asynchronous.
time.Sleep(time.Second * 2)
ticker := time.NewTicker(10 * time.Millisecond)
select {
case <-ticker.C:
if n.IsRunning() {
return
}
case <-time.After(5 * time.Second):
t.Fatal("timed out waiting for start")
}
ch := make(chan struct{}, 1)
go func() {
n.Stop()
ch <- struct{}{}
}()
ticker := time.NewTicker(time.Second * 5)
select {
case <-ch:
case <-ticker.C:
case <-n.Quit:
case <-time.After(5 * time.Second):
t.Fatal("timed out waiting for shutdown")
}
}