Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
go test -race -timeout 1800s -count 1 github.com/cosmos/cosmos-sdk/types/mempool
  • Loading branch information
mmsqe committed Aug 21, 2024
1 parent 6b09168 commit 77def03
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions types/mempool/priority_nonce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math"
"math/rand"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -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()
})
}
}
Expand Down

0 comments on commit 77def03

Please sign in to comment.