Skip to content

fix: TestTxPool_ConcurrentlyAddingTx #1501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions mempool/cat/pool_test.go
Original file line number Diff line number Diff line change
@@ -721,7 +721,8 @@ func abciResponses(n int, code uint32) []*abci.ResponseDeliverTx {
}

func TestTxPool_ConcurrentlyAddingTx(t *testing.T) {
txmp := setup(t, 500)
cacheSize := 500
txPool := setup(t, cacheSize)
tx := types.Tx("sender=0000=1")

numTxs := 10
@@ -731,7 +732,7 @@ func TestTxPool_ConcurrentlyAddingTx(t *testing.T) {
wg.Add(1)
go func(sender uint16) {
defer wg.Done()
_, err := txmp.TryAddNewTx(tx, tx.Key(), mempool.TxInfo{SenderID: sender})
_, err := txPool.TryAddNewTx(tx, tx.Key(), mempool.TxInfo{SenderID: sender})
errCh <- err
}(uint16(i + 1))
}
@@ -747,7 +748,10 @@ func TestTxPool_ConcurrentlyAddingTx(t *testing.T) {
errCount++
}
}
require.Equal(t, numTxs-1, errCount)
// At least one tx should succeed and get added to the mempool without an error.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least one tx should succeed and get added to the mempool without an error.

I've already approved it, but I was thinking we should maybe set it to 2, or something higher than 1, to ensure the concurrent adding works properly.

require.Less(t, errCount, numTxs)
// The rest of the txs may fail with ErrTxInMempool but the number of errors isn't exact.
require.LessOrEqual(t, errCount, numTxs-1)
}

func TestTxPool_BroadcastQueue(t *testing.T) {
Loading