From af2a7e3ace3b5298d84f46add83e5bf23389645e Mon Sep 17 00:00:00 2001 From: Sanaz Taheri <35961250+staheri14@users.noreply.github.com> Date: Wed, 19 Jun 2024 14:46:31 -0700 Subject: [PATCH] test: backports knuu optimizations from 3493 (#3515) Closes #3480 This PR backports many optimizations introduced in the big block tests via https://github.com/celestiaorg/celestia-app/pull/3493 to the `main` branch. Will be ready for review after merging https://github.com/celestiaorg/celestia-app/pull/3514 --------- Co-authored-by: Evan Forbes <42654277+evan-forbes@users.noreply.github.com> --- test/e2e/testnet/node.go | 25 +++++++-- test/e2e/testnet/test_helpers.go | 11 ++++ test/e2e/testnet/testnet.go | 93 ++++++++++++++------------------ 3 files changed, 72 insertions(+), 57 deletions(-) diff --git a/test/e2e/testnet/node.go b/test/e2e/testnet/node.go index 46a9db708e..c47f5007ff 100644 --- a/test/e2e/testnet/node.go +++ b/test/e2e/testnet/node.go @@ -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 @@ -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 } diff --git a/test/e2e/testnet/test_helpers.go b/test/e2e/testnet/test_helpers.go index a3de3cf4c3..d507c17fc5 100644 --- a/test/e2e/testnet/test_helpers.go +++ b/test/e2e/testnet/test_helpers.go @@ -1,6 +1,7 @@ package testnet import ( + "fmt" "log" ) @@ -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) +} diff --git a/test/e2e/testnet/testnet.go b/test/e2e/testnet/testnet.go index 394d6eada5..b16b51ad9f 100644 --- a/test/e2e/testnet/testnet.go +++ b/test/e2e/testnet/testnet.go @@ -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 } @@ -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). @@ -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 } @@ -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) } @@ -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 { @@ -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") } } }