From ed4b4346b03a417e808f52906aeeaa9a0276b9b0 Mon Sep 17 00:00:00 2001 From: Calvin Wang Date: Sun, 23 Jul 2023 16:18:34 +1000 Subject: [PATCH] speed up race detector tests --- pkg/cosmos/client/client_test.go | 6 ++---- pkg/cosmos/client/test_helpers.go | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/cosmos/client/client_test.go b/pkg/cosmos/client/client_test.go index e2149cb2..e86c2762 100644 --- a/pkg/cosmos/client/client_test.go +++ b/pkg/cosmos/client/client_test.go @@ -341,21 +341,19 @@ func TestCosmosClient(t *testing.T) { require.NoError(t, err) resp, err := tc.SignAndBroadcast([]sdk.Msg{rawMsg}, an, sn, tt.gasPrice, accounts[0].PrivateKey, txtypes.BroadcastMode_BROADCAST_MODE_SYNC) require.NotNil(t, resp) - tx, success := awaitTxCommitted(t, tc, resp.TxResponse.TxHash) if tt.expCode == 0 { require.NoError(t, err) + tx, success := awaitTxCommitted(t, tc, resp.TxResponse.TxHash) require.True(t, success) require.Equal(t, types.CodeTypeOK, tx.TxResponse.Code) require.Equal(t, "", tx.TxResponse.Codespace) require.Equal(t, tt.expCode, tx.TxResponse.Code) + require.Equal(t, resp.TxResponse.TxHash, tx.TxResponse.TxHash) t.Log("Fee:", tx.Tx.GetFee()) t.Log("Height:", tx.TxResponse.Height) - require.Equal(t, tx.TxResponse.TxHash, tx.TxResponse.TxHash) } else { require.Error(t, err) - require.False(t, success) - require.Nil(t, tx) require.Equal(t, expCodespace, resp.TxResponse.Codespace) require.Equal(t, tt.expCode, resp.TxResponse.Code) } diff --git a/pkg/cosmos/client/test_helpers.go b/pkg/cosmos/client/test_helpers.go index a9d42d87..348ab058 100644 --- a/pkg/cosmos/client/test_helpers.go +++ b/pkg/cosmos/client/test_helpers.go @@ -217,11 +217,12 @@ func mustRandomPort() int { // awaitTxCommitted waits for a transaction to be committed on chain and returns the tx receipt func awaitTxCommitted(t *testing.T, tc *Client, txHash string) (response *txtypes.GetTxResponse, success bool) { - for i := 0; i < 10; i++ { // max poll attempts to wait for tx commitment + for i := 0; i < 9; i++ { // max poll attempts to wait for tx commitment txReceipt, err := tc.Tx(txHash) if err == nil { return txReceipt, true } + t.Logf("tx not committed yet (attempt %d)", i+1) time.Sleep(time.Second * 1) // TODO: configure dynamically based on block times } return nil, false