From cf2b0ba512e0ceddea8ee135d43105f82e33488c Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 21 Aug 2024 11:46:58 +0800 Subject: [PATCH] add test go test -race -timeout 1800s -count 1 github.com/cosmos/cosmos-sdk/types/mempool --- types/mempool/priority_nonce_test.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/types/mempool/priority_nonce_test.go b/types/mempool/priority_nonce_test.go index e071bd55ca03..b6acda971298 100644 --- a/types/mempool/priority_nonce_test.go +++ b/types/mempool/priority_nonce_test.go @@ -4,6 +4,7 @@ import ( "fmt" "math" "math/rand" + "sync" "testing" "time" @@ -384,14 +385,28 @@ func (s *MempoolTestSuite) TestIterator() { } // iterate through txs + wg := new(sync.WaitGroup) + wg.Add(1) + go func() { + for j := len(tt.txs); j < len(tt.txs)+100; j++ { + tx := testTx{id: j, priority: int64(rand.Intn(100)), nonce: uint64(j), address: sa} + c := ctx.WithPriority(tx.priority) + _ = pool.Insert(c, tx) + } + wg.Done() + }() + iterator := pool.Select(ctx, nil) for iterator != nil { tx := iterator.Tx().Tx.(testTx) - require.Equal(t, tt.txs[tx.id].p, int(tx.priority)) - require.Equal(t, tt.txs[tx.id].n, int(tx.nonce)) - require.Equal(t, tt.txs[tx.id].a, tx.address) + if tx.id < len(tt.txs) { + require.Equal(t, tt.txs[tx.id].p, int(tx.priority)) + require.Equal(t, tt.txs[tx.id].n, int(tx.nonce)) + require.Equal(t, tt.txs[tx.id].a, tx.address) + } iterator = iterator.Next() } + wg.Wait() }) } }