Disable block timeouts in E2E test network #19

Merged
ashwin merged 5 commits from pm-variable-timeout into main 2024-03-12 04:35:21 +00:00
6 changed files with 31 additions and 22 deletions
Showing only changes of commit ce005bc725 - Show all commits

View File

@ -15,6 +15,7 @@ import (
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
"git.vdb.to/cerc-io/laconic2d/testutil/network"
types "git.vdb.to/cerc-io/laconic2d/x/auction"
"git.vdb.to/cerc-io/laconic2d/x/auction/client/cli"
@ -49,7 +50,7 @@ func (ets *E2ETestSuite) SetupSuite() { //nolint: all
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
sr.NoError(err)
_, err = ets.network.WaitForHeight(1)
_, err = ets.network.WaitForHeight(1, e2e.TenSeconds)
sr.NoError(err)
// setting up random owner and bidder accounts
@ -90,7 +91,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
*accountAddress = newAddr.String()
// wait for tx to take effect
err = ets.network.WaitForNextBlock()
err = ets.network.WaitForNextBlock(e2e.TenSeconds)
sr.NoError(err)
}

View File

@ -8,6 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction"
"git.vdb.to/cerc-io/laconic2d/x/auction/client/cli"
)
@ -96,7 +97,7 @@ func (ets *E2ETestSuite) executeTx(cmd *cobra.Command, args []string, caller str
return sdk.TxResponse{}, err
}
err = ets.network.WaitForNextBlock()
err = ets.network.WaitForNextBlock(e2e.TenSeconds)
if err != nil {
return sdk.TxResponse{}, err
}

View File

@ -13,6 +13,7 @@ import (
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
"git.vdb.to/cerc-io/laconic2d/testutil/network"
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
"git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
@ -41,7 +42,7 @@ func (ets *E2ETestSuite) SetupSuite() { //nolint: all
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
sr.NoError(err)
_, err = ets.network.WaitForHeight(1)
_, err = ets.network.WaitForHeight(1, e2e.TenSeconds)
sr.NoError(err)
// setting up random account
@ -78,7 +79,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
*accountAddress = newAddr.String()
// wait for tx to take effect
err = ets.network.WaitForNextBlock()
err = ets.network.WaitForNextBlock(e2e.TenSeconds)
sr.NoError(err)
}
@ -102,7 +103,7 @@ func (ets *E2ETestSuite) createBond() string {
sr.Zero(d.Code)
// wait for tx to take effect
err = ets.network.WaitForNextBlock()
err = ets.network.WaitForNextBlock(e2e.TenSeconds)
sr.NoError(err)
// getting the bonds list and returning the bond-id

View File

@ -3,6 +3,7 @@ package e2e
import (
"fmt"
"os"
"time"
"cosmossdk.io/log"
pruningtypes "cosmossdk.io/store/pruning/types"
@ -25,6 +26,10 @@ import (
"git.vdb.to/cerc-io/laconic2d/testutil/network"
)
const (
TenSeconds = 10 * time.Second
)
// NewTestNetworkFixture returns a new LaconicApp AppConstructor for network simulation tests
func NewTestNetworkFixture() network.TestFixture {
dir, err := os.MkdirTemp("", "laconic")

View File

@ -15,6 +15,7 @@ import (
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
"git.vdb.to/cerc-io/laconic2d/testutil/network"
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
bondcli "git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
@ -58,7 +59,7 @@ func (ets *E2ETestSuite) SetupSuite() {
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
sr.NoError(err)
_, err = ets.network.WaitForHeight(2)
_, err = ets.network.WaitForHeight(2, 2*e2e.TenSeconds)
sr.NoError(err)
// setting up random account
@ -97,7 +98,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
*accountAddress = newAddr.String()
// wait for tx to take effect
err = ets.network.WaitForNextBlock()
err = ets.network.WaitForNextBlock(e2e.TenSeconds)
sr.NoError(err)
}
@ -121,7 +122,7 @@ func (ets *E2ETestSuite) createBond() string {
sr.Zero(d.Code)
// wait for tx to take effect
err = ets.network.WaitForNextBlock()
err = ets.network.WaitForNextBlock(e2e.TenSeconds)
sr.NoError(err)
// getting the bonds list and returning the bond-id
@ -164,7 +165,7 @@ func (ets *E2ETestSuite) reserveName(authorityName string) {
sr.NoError(err)
sr.Zero(d.Code)
err = ets.network.WaitForNextBlock()
err = ets.network.WaitForNextBlock(e2e.TenSeconds)
sr.NoError(err)
}
@ -191,7 +192,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) {
sr.NoError(err)
sr.Zero(d.Code)
err = ets.network.WaitForNextBlock()
err = ets.network.WaitForNextBlock(e2e.TenSeconds)
sr.NoError(err)
// Get the bond-id
@ -214,7 +215,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) {
sr.NoError(err)
sr.Zero(d.Code)
err = ets.network.WaitForNextBlock()
err = ets.network.WaitForNextBlock(e2e.TenSeconds)
sr.NoError(err)
args = []string{
@ -235,7 +236,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) {
sr.NoError(err)
sr.Zero(d.Code)
err = ets.network.WaitForNextBlock()
err = ets.network.WaitForNextBlock(e2e.TenSeconds)
sr.NoError(err)
}
@ -265,7 +266,7 @@ func (ets *E2ETestSuite) createRecord(bondId string) {
sr.NoError(err)
sr.Zero(d.Code, d.RawLog)
err = ets.network.WaitForNextBlock()
err = ets.network.WaitForNextBlock(e2e.TenSeconds)
sr.NoError(err)
}

View File

@ -659,7 +659,7 @@ func trapSignal(cleanupFunc func()) {
// LatestHeight returns the latest height of the network or an error if the
// query fails or no validators exist.
func (n *Network) LatestHeight() (int64, error) {
func (n *Network) LatestHeight(t time.Duration) (int64, error) {
if len(n.Validators) == 0 {
return 0, errors.New("no validators available")
}
@ -667,7 +667,7 @@ func (n *Network) LatestHeight() (int64, error) {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
timeout := time.NewTimer(time.Second * 5)
timeout := time.NewTimer(t)
defer timeout.Stop()
var latestHeight int64
@ -702,8 +702,8 @@ func (n *Network) LatestHeight() (int64, error) {
// WaitForHeight performs a blocking check where it waits for a block to be
// committed after a given block. If that height is not reached within a timeout,
// an error is returned. Regardless, the latest height queried is returned.
func (n *Network) WaitForHeight(h int64) (int64, error) {
return n.WaitForHeightWithTimeout(h, 10*time.Second)
func (n *Network) WaitForHeight(h int64, t time.Duration) (int64, error) {
return n.WaitForHeightWithTimeout(h, t)
}
// WaitForHeightWithTimeout is the same as WaitForHeight except the caller can
@ -745,7 +745,7 @@ func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, err
// blocks has been reached.
func (n *Network) RetryForBlocks(retryFunc func() error, blocks int) error {
for i := 0; i < blocks; i++ {
_ = n.WaitForNextBlock()
_ = n.WaitForNextBlock(10 * time.Second)
err := retryFunc()
if err == nil {
return nil
@ -760,13 +760,13 @@ func (n *Network) RetryForBlocks(retryFunc func() error, blocks int) error {
// WaitForNextBlock waits for the next block to be committed, returning an error
// upon failure.
func (n *Network) WaitForNextBlock() error {
lastBlock, err := n.LatestHeight()
func (n *Network) WaitForNextBlock(t time.Duration) error {
lastBlock, err := n.LatestHeight(t)
if err != nil {
return err
}
_, err = n.WaitForHeight(lastBlock + 1)
_, err = n.WaitForHeight(lastBlock+1, t)
if err != nil {
return err
}