test(client/rpc): Fix flacky RPC client test (#24260)
This commit is contained in:
parent
76a25e022c
commit
b25ecf398e
@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
@ -60,40 +61,50 @@ func (s *IntegrationTestSuite) TestCLIQueryConn() {
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryABCIHeight() {
|
||||
testCases := []struct {
|
||||
name string
|
||||
reqHeight int64
|
||||
ctxHeight int64
|
||||
expHeight int64
|
||||
name string
|
||||
reqHeight int64
|
||||
ctxHeight int64
|
||||
awaitMinChainHeight int64
|
||||
assertFn func(t *testing.T, latestHeightAtQuery int64, resp abci.ResponseQuery)
|
||||
}{
|
||||
{
|
||||
name: "non zero request height",
|
||||
reqHeight: 3,
|
||||
ctxHeight: 1, // query at height 1 or 2 would cause an error
|
||||
expHeight: 3,
|
||||
name: "request height set",
|
||||
reqHeight: 2, // no proof when < 2
|
||||
ctxHeight: 1,
|
||||
awaitMinChainHeight: 3, // wait +1 block to be on the safe side
|
||||
assertFn: func(t *testing.T, _ int64, resp abci.ResponseQuery) {
|
||||
t.Helper()
|
||||
assert.Equal(t, int64(2), resp.Height)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty request height - use context height",
|
||||
reqHeight: 0,
|
||||
ctxHeight: 3,
|
||||
expHeight: 3,
|
||||
name: "fallback to context height when request height is not set",
|
||||
reqHeight: 0,
|
||||
ctxHeight: 3,
|
||||
awaitMinChainHeight: 4, // wait +1 block to be on the safe side
|
||||
assertFn: func(t *testing.T, _ int64, resp abci.ResponseQuery) {
|
||||
t.Helper()
|
||||
assert.Equal(t, int64(3), resp.Height)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty request height and context height - use latest height",
|
||||
reqHeight: 0,
|
||||
ctxHeight: 0,
|
||||
expHeight: 4,
|
||||
name: "with empty values, use latest height",
|
||||
reqHeight: 0,
|
||||
ctxHeight: 0,
|
||||
awaitMinChainHeight: 2, // no proof when < 2
|
||||
assertFn: func(t *testing.T, latestHeightAtQuery int64, resp abci.ResponseQuery) {
|
||||
t.Helper()
|
||||
anyOf := []int64{latestHeightAtQuery, latestHeightAtQuery - 1}
|
||||
assert.Contains(t, anyOf, resp.Height)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
gotHeight, err := s.network.WaitForHeight(tc.expHeight)
|
||||
if gotHeight != tc.expHeight {
|
||||
s.Fail(err.Error())
|
||||
}
|
||||
currentHeight, err := s.network.WaitForHeight(tc.awaitMinChainHeight)
|
||||
s.Require().NoError(err)
|
||||
|
||||
val := s.network.Validators[0]
|
||||
|
||||
clientCtx := val.ClientCtx
|
||||
clientCtx = clientCtx.WithHeight(tc.ctxHeight)
|
||||
|
||||
@ -106,8 +117,7 @@ func (s *IntegrationTestSuite) TestQueryABCIHeight() {
|
||||
|
||||
res, err := clientCtx.QueryABCI(req)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().Equal(tc.expHeight, res.Height)
|
||||
tc.assertFn(s.T(), currentHeight, res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user