Skip to content

Commit

Permalink
test: makes network latency effective at earlier heights in benchmark…
Browse files Browse the repository at this point in the history
… tests (#3747)

Closes #3746
  • Loading branch information
staheri14 authored Aug 1, 2024
1 parent 9588fc4 commit fc68533
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 20 deletions.
20 changes: 18 additions & 2 deletions test/e2e/benchmark/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ func (b *BenchmarkTest) SetupNodes() error {

// Run runs the benchmark test for the specified duration in the manifest.
func (b *BenchmarkTest) Run() error {
log.Println("Starting testnet")
err := b.Start()
log.Println("Starting benchmark testnet")

log.Println("Starting nodes")
err := b.StartNodes()
if err != nil {
return fmt.Errorf("failed to start testnet: %v", err)
}
Expand All @@ -116,6 +118,20 @@ func (b *BenchmarkTest) Run() error {
}
}

// wait for the nodes to sync
log.Println("Waiting for nodes to sync")
err = b.WaitToSync()
if err != nil {
return err
}

// start tx clients
log.Println("Starting tx clients")
err = b.StartTxClients()
if err != nil {
return fmt.Errorf("failed to start tx clients: %v", err)
}

// wait some time for the tx clients to submit transactions
time.Sleep(b.manifest.TestDuration)

Expand Down
65 changes: 47 additions & 18 deletions test/e2e/testnet/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,30 +323,15 @@ func (t *Testnet) RemoteRPCEndpoints() ([]string, error) {
return rpcEndpoints, nil
}

func (t *Testnet) Start() error {
// WaitToSync waits for the started nodes to sync with the network and move
// past the genesis block.
func (t *Testnet) WaitToSync() error {
genesisNodes := make([]*Node, 0)
for _, node := range t.nodes {
if node.StartHeight == 0 {
genesisNodes = append(genesisNodes, node)
}
}
// start genesis nodes asynchronously
for _, node := range genesisNodes {
err := node.StartAsync()
if err != nil {
return fmt.Errorf("node %s failed to start: %w", node.Name, err)
}
}
log.Info().Msg("forwarding ports for genesis nodes")
// wait for instances to be running
for _, node := range genesisNodes {
err := node.WaitUntilStartedAndForwardPorts()
if err != nil {
return fmt.Errorf("node %s failed to start: %w", node.Name, err)
}
}
// wait for nodes to sync
log.Info().Msg("waiting for genesis nodes to sync")
for _, node := range genesisNodes {
log.Info().Str("name", node.Name).Msg(
"waiting for node to sync")
Expand All @@ -373,6 +358,50 @@ func (t *Testnet) Start() error {
time.Sleep(time.Duration(i) * time.Second)
}
}
return nil
}

// StartNodes starts the testnet nodes and forwards the ports.
// It does not wait for the nodes to produce blocks.
// For that, use WaitToSync.
func (t *Testnet) StartNodes() error {
genesisNodes := make([]*Node, 0)
for _, node := range t.nodes {
if node.StartHeight == 0 {
genesisNodes = append(genesisNodes, node)
}
}
// start genesis nodes asynchronously
for _, node := range genesisNodes {
err := node.StartAsync()
if err != nil {
return fmt.Errorf("node %s failed to start: %w", node.Name, err)
}
}
log.Info().Msg("forwarding ports for genesis nodes")
// wait for instances to be running
for _, node := range genesisNodes {
err := node.WaitUntilStartedAndForwardPorts()
if err != nil {
return fmt.Errorf("node %s failed to start: %w", node.Name, err)
}
}
return nil
}

func (t *Testnet) Start() error {
// start nodes and forward ports
err := t.StartNodes()
if err != nil {
return err
}
// wait for nodes to sync
log.Info().Msg("waiting for genesis nodes to sync")
err = t.WaitToSync()
if err != nil {
return err
}

return t.StartTxClients()
}

Expand Down

0 comments on commit fc68533

Please sign in to comment.