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.

45 lines
996 B

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. n.Start()
  17. t.Logf("Started node %v", n.sw.NodeInfo())
  18. // wait for the node to produce a block
  19. blockCh := make(chan interface{})
  20. err = n.EventBus().Subscribe(context.Background(), "node_test", types.EventQueryNewBlock, blockCh)
  21. assert.NoError(t, err)
  22. select {
  23. case <-blockCh:
  24. case <-time.After(5 * time.Second):
  25. t.Fatal("timed out waiting for the node to produce a block")
  26. }
  27. // stop the node
  28. go func() {
  29. n.Stop()
  30. }()
  31. select {
  32. case <-n.Quit:
  33. case <-time.After(5 * time.Second):
  34. t.Fatal("timed out waiting for shutdown")
  35. }
  36. }