2015-07-21 18:15:40 -04:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2016-03-06 15:05:50 -08:00
|
|
|
"github.com/tendermint/tendermint/config/tendermint_test"
|
2015-07-21 18:15:40 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNodeStartStop(t *testing.T) {
|
2017-05-01 22:14:37 -04:00
|
|
|
viperConfig := tendermint_test.ResetConfig("node_node_test")
|
|
|
|
config := ConfigFromViper(viperConfig)
|
2015-12-01 20:12:01 -08:00
|
|
|
|
2015-07-21 18:15:40 -04:00
|
|
|
// Create & start node
|
2016-09-09 23:55:24 -04:00
|
|
|
n := NewNodeDefault(config)
|
2015-07-21 18:15:40 -04:00
|
|
|
n.Start()
|
|
|
|
log.Notice("Started node", "nodeInfo", n.sw.NodeInfo())
|
2017-01-15 16:59:10 -08:00
|
|
|
|
|
|
|
// Wait a bit to initialize
|
|
|
|
// TODO remove time.Sleep(), make asynchronous.
|
2015-07-21 18:15:40 -04:00
|
|
|
time.Sleep(time.Second * 2)
|
2017-01-15 16:59:10 -08:00
|
|
|
|
2015-07-21 18:15:40 -04:00
|
|
|
ch := make(chan struct{}, 1)
|
|
|
|
go func() {
|
|
|
|
n.Stop()
|
|
|
|
ch <- struct{}{}
|
|
|
|
}()
|
|
|
|
ticker := time.NewTicker(time.Second * 5)
|
|
|
|
select {
|
|
|
|
case <-ch:
|
|
|
|
case <-ticker.C:
|
|
|
|
t.Fatal("timed out waiting for shutdown")
|
|
|
|
}
|
|
|
|
}
|