You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
963 B

  1. package node
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/tendermint/go-p2p"
  6. "github.com/tendermint/tendermint/config/tendermint_test"
  7. "github.com/tendermint/tendermint/types"
  8. )
  9. func TestNodeStartStop(t *testing.T) {
  10. config := tendermint_test.ResetConfig("node_node_test")
  11. // Get PrivValidator
  12. privValidatorFile := config.GetString("priv_validator_file")
  13. privValidator := types.LoadOrGenPrivValidator(privValidatorFile)
  14. // Create & start node
  15. n := NewNode(config, privValidator)
  16. protocol, address := ProtocolAndAddress(config.GetString("node_laddr"))
  17. l := p2p.NewDefaultListener(protocol, address, config.GetBool("skip_upnp"))
  18. n.AddListener(l)
  19. n.Start()
  20. log.Notice("Started node", "nodeInfo", n.sw.NodeInfo())
  21. time.Sleep(time.Second * 2)
  22. ch := make(chan struct{}, 1)
  23. go func() {
  24. n.Stop()
  25. ch <- struct{}{}
  26. }()
  27. ticker := time.NewTicker(time.Second * 5)
  28. select {
  29. case <-ch:
  30. case <-ticker.C:
  31. t.Fatal("timed out waiting for shutdown")
  32. }
  33. }