Skip to content

Commit

Permalink
speed up race detector tests
Browse files Browse the repository at this point in the history
  • Loading branch information
calvwang9 committed Jul 23, 2023
1 parent 1fc36a0 commit ed4b434
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 2 additions & 4 deletions pkg/cosmos/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cosmos/client/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed4b434

Please sign in to comment.