Skip to content

Commit 9327f2b

Browse files
authoredSep 25, 2024··
fix: TestTxPool_ConcurrentlyAddingTx (#1501)
Closes #1383 ## Testing ``` $ go test ./... -run "TestTxPool_ConcurrentlyAddingTx" -count=1000 ok github.com/tendermint/tendermint/mempool/cat 0.402s ```
1 parent 4392e84 commit 9327f2b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed
 

‎mempool/cat/pool_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,8 @@ func abciResponses(n int, code uint32) []*abci.ResponseDeliverTx {
721721
}
722722

723723
func TestTxPool_ConcurrentlyAddingTx(t *testing.T) {
724-
txmp := setup(t, 500)
724+
cacheSize := 500
725+
txPool := setup(t, cacheSize)
725726
tx := types.Tx("sender=0000=1")
726727

727728
numTxs := 10
@@ -731,7 +732,7 @@ func TestTxPool_ConcurrentlyAddingTx(t *testing.T) {
731732
wg.Add(1)
732733
go func(sender uint16) {
733734
defer wg.Done()
734-
_, err := txmp.TryAddNewTx(tx, tx.Key(), mempool.TxInfo{SenderID: sender})
735+
_, err := txPool.TryAddNewTx(tx, tx.Key(), mempool.TxInfo{SenderID: sender})
735736
errCh <- err
736737
}(uint16(i + 1))
737738
}
@@ -747,7 +748,10 @@ func TestTxPool_ConcurrentlyAddingTx(t *testing.T) {
747748
errCount++
748749
}
749750
}
750-
require.Equal(t, numTxs-1, errCount)
751+
// At least one tx should succeed and get added to the mempool without an error.
752+
require.Less(t, errCount, numTxs)
753+
// The rest of the txs may fail with ErrTxInMempool but the number of errors isn't exact.
754+
require.LessOrEqual(t, errCount, numTxs-1)
751755
}
752756

753757
func TestTxPool_BroadcastQueue(t *testing.T) {

0 commit comments

Comments
 (0)
Please sign in to comment.