Skip to content

Commit

Permalink
test: backports knuu optimizations from 3493 (#3515)
Browse files Browse the repository at this point in the history
Closes #3480 
This PR backports many optimizations introduced in the big block tests
via #3493 to the `main`
branch.

Will be ready for review after merging
#3514

---------

Co-authored-by: Evan Forbes <[email protected]>
  • Loading branch information
staheri14 and evan-forbes authored Jun 19, 2024
1 parent 95c8cd7 commit af2a7e3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 57 deletions.
25 changes: 21 additions & 4 deletions test/e2e/testnet/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,15 @@ func (n *Node) Init(genesis *types.GenesisDoc, peers []string, configOptions ...
return fmt.Errorf("writing address book: %w", err)
}

if err := n.Instance.AddFolder(nodeDir, remoteRootDir, "10001:10001"); err != nil {
return fmt.Errorf("copying over node %s directory: %w", n.Name, err)
err = n.Instance.Commit()
if err != nil {
return fmt.Errorf("committing instance: %w", err)
}

return n.Instance.Commit()
if err = n.Instance.AddFolder(nodeDir, remoteRootDir, "10001:10001"); err != nil {
return fmt.Errorf("copying over node %s directory: %w", n.Name, err)
}
return nil
}

// AddressP2P returns a P2P endpoint address for the node. This is used for
Expand Down Expand Up @@ -296,10 +300,23 @@ func (n Node) Client() (*http.HTTP, error) {
}

func (n *Node) Start() error {
if err := n.Instance.Start(); err != nil {
if err := n.StartAsync(); err != nil {
return err
}
if err := n.WaitUntilStartedAndForwardPorts(); err != nil {
return err
}
return nil
}

func (n *Node) StartAsync() error {
if err := n.Instance.StartAsync(); err != nil {
return err
}
return nil
}

func (n *Node) WaitUntilStartedAndForwardPorts() error {
if err := n.Instance.WaitInstanceIsRunning(); err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/testnet/test_helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testnet

import (
"fmt"
"log"
)

Expand All @@ -9,3 +10,13 @@ func NoError(message string, err error) {
log.Fatalf("%s: %v", message, err)
}
}

type JSONRPCError struct {
Code int
Message string
Data string
}

func (e *JSONRPCError) Error() string {
return fmt.Sprintf("JSONRPC Error - Code: %d, Message: %s, Data: %s", e.Code, e.Message, e.Data)
}
93 changes: 40 additions & 53 deletions test/e2e/testnet/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,21 @@ func (t *Testnet) CreateTxClient(name,
Msg("error creating txsim")
return err
}

// copy over the keyring directory to the txsim instance
err = txsim.Instance.AddFolder(txsimKeyringDir, txsimRootDir, "10001:10001")
err = txsim.Instance.Commit()
if err != nil {
log.Err(err).
Str("directory", txsimKeyringDir).
Str("name", name).
Msg("error adding keyring dir to txsim")
Msg("error committing txsim")
return err
}

err = txsim.Instance.Commit()
// copy over the keyring directory to the txsim instance
err = txsim.Instance.AddFolder(txsimKeyringDir, txsimRootDir, "10001:10001")
if err != nil {
log.Err(err).
Str("directory", txsimKeyringDir).
Str("name", name).
Msg("error committing txsim")
Msg("error adding keyring dir to txsim")
return err
}

Expand All @@ -167,7 +166,7 @@ func (t *Testnet) CreateTxClient(name,

func (t *Testnet) StartTxClients() error {
for _, txsim := range t.txClients {
err := txsim.Instance.Start()
err := txsim.Instance.StartWithoutWait()
if err != nil {
log.Err(err).
Str("name", txsim.Name).
Expand All @@ -178,6 +177,13 @@ func (t *Testnet) StartTxClients() error {
Str("name", txsim.Name).
Msg("txsim started")
}
// wait for txsims to start
for _, txsim := range t.txClients {
err := txsim.Instance.WaitInstanceIsRunning()
if err != nil {
return fmt.Errorf("txsim %s failed to start: %w", txsim.Name, err)
}
}
return nil
}

Expand Down Expand Up @@ -321,8 +327,9 @@ func (t *Testnet) Start() error {
genesisNodes = append(genesisNodes, node)
}
}
// start genesis nodes asynchronously
for _, node := range genesisNodes {
err := node.Start()
err := node.StartAsync()
if err != nil {
return fmt.Errorf("node %s failed to start: %w", node.Name, err)
}
Expand All @@ -331,6 +338,14 @@ func (t *Testnet) Start() error {
if err != nil {
return err
}
// 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
for _, node := range genesisNodes {
client, err := node.Client()
if err != nil {
Expand All @@ -351,58 +366,30 @@ func (t *Testnet) Start() error {
if i == 9 {
return fmt.Errorf("failed to start node %s", node.Name)
}
time.Sleep(time.Second)
fmt.Printf("node %s is not synced yet, waiting...\n", node.Name)
time.Sleep(100 * time.Millisecond)
}
}
return nil
}

func (t *Testnet) Cleanup() {
for _, node := range t.nodes {
if node.Instance.IsInState(knuu.Started) {
if err := node.Instance.Stop(); err != nil {
log.Err(err).
Str("name", node.Name).
Msg("node failed to stop")
continue
}
if err := node.Instance.WaitInstanceIsStopped(); err != nil {
log.Err(err).
Str("name", node.Name).
Msg("node failed to stop")
continue
}
}
if node.Instance.IsInState(knuu.Started, knuu.Stopped) {
err := node.Instance.Destroy()
if err != nil {
log.Err(err).
Str("name", node.Name).
Msg("node failed to cleanup")
}
// cleanup txsim
for _, txsim := range t.txClients {
err := txsim.Instance.Destroy()
if err != nil {
log.Err(err).
Str("name", txsim.Name).
Msg("txsim failed to cleanup")
}
}
// stop and cleanup txsim
for _, txsim := range t.txClients {
if txsim.Instance.IsInState(knuu.Started) {
err := txsim.Instance.Stop()
if err != nil {
log.Err(err).
Str("name", txsim.Name).
Msg("txsim failed to stop")
}
err = txsim.Instance.WaitInstanceIsStopped()
if err != nil {
log.Err(err).
Str("name", txsim.Name).
Msg("failed to wait for txsim to stop")
}
err = txsim.Instance.Destroy()
if err != nil {
log.Err(err).
Str("name", txsim.Name).
Msg("txsim failed to cleanup")
}
// cleanup nodes
for _, node := range t.nodes {
err := node.Instance.Destroy()
if err != nil {
log.Err(err).
Str("name", node.Name).
Msg("node failed to cleanup")
}
}
}
Expand Down

0 comments on commit af2a7e3

Please sign in to comment.