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.

34 lines
967 B

  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. e2e "github.com/tendermint/tendermint/test/e2e/pkg"
  6. )
  7. // Wait waits for a number of blocks to be produced, and for all nodes to catch
  8. // up with it.
  9. func Wait(testnet *e2e.Testnet, blocks int64) error {
  10. block, _, err := waitForHeight(testnet, 0)
  11. if err != nil {
  12. return err
  13. }
  14. return WaitUntil(testnet, block.Height+blocks)
  15. }
  16. // WaitUntil waits until a given height has been reached.
  17. func WaitUntil(testnet *e2e.Testnet, height int64) error {
  18. logger.Info(fmt.Sprintf("Waiting for all nodes to reach height %v...", height))
  19. _, err := waitForAllNodes(testnet, height, waitingTime(len(testnet.Nodes)))
  20. if err != nil {
  21. return err
  22. }
  23. return nil
  24. }
  25. // waitingTime estimates how long it should take for a node to reach the height.
  26. // More nodes in a network implies we may expect a slower network and may have to wait longer.
  27. func waitingTime(nodes int) time.Duration {
  28. return time.Duration(20+(nodes*2)) * time.Second
  29. }