github.com/vipernet-xyz/tm@v0.34.24/test/e2e/runner/wait.go (about)

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