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.

48 lines
1.0 KiB

8 years ago
8 years ago
8 years ago
  1. package node
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/tendermint/tmlibs/log"
  8. cfg "github.com/tendermint/tendermint/config"
  9. "github.com/tendermint/tendermint/types"
  10. )
  11. func TestNodeStartStop(t *testing.T) {
  12. config := cfg.ResetTestRoot("node_node_test")
  13. // create & start node
  14. n, err := DefaultNewNode(config, log.TestingLogger())
  15. assert.NoError(t, err, "expected no err on DefaultNewNode")
  16. err1 := n.Start()
  17. if err1 != nil {
  18. t.Error(err1)
  19. }
  20. t.Logf("Started node %v", n.sw.NodeInfo())
  21. // wait for the node to produce a block
  22. blockCh := make(chan interface{})
  23. err = n.EventBus().Subscribe(context.Background(), "node_test", types.EventQueryNewBlock, blockCh)
  24. assert.NoError(t, err)
  25. select {
  26. case <-blockCh:
  27. case <-time.After(5 * time.Second):
  28. t.Fatal("timed out waiting for the node to produce a block")
  29. }
  30. // stop the node
  31. go func() {
  32. n.Stop()
  33. }()
  34. select {
  35. case <-n.Quit():
  36. case <-time.After(5 * time.Second):
  37. t.Fatal("timed out waiting for shutdown")
  38. }
  39. }