From 4178c273f4cfc3fa4d403f6ad6ea70c81960f427 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Wed, 12 Aug 2026 11:16:33 +0800 Subject: [PATCH] test(core/txpool/legacypool): drop shared config writes from parallel tests TestQueueAccountLimiting and TestPendingLimiting both run with t.Parallel() and both assigned testTxPoolConfig.AccountQueue, a package-level variable that every other test reads while building its pool. That is a data race, and it can also change the limits another test is asserting against. Neither test needs the global: their pools are already constructed before the assignment, so the value only ever served as the loop bound. Use a local accountQueue instead. Also fix the mismatched want value in the pending count error message, which printed AccountQueue+5 for an equality check against AccountQueue. --- core/txpool/legacypool/legacypool_test.go | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/core/txpool/legacypool/legacypool_test.go b/core/txpool/legacypool/legacypool_test.go index f86f10a7325e..dbcc4bd86580 100644 --- a/core/txpool/legacypool/legacypool_test.go +++ b/core/txpool/legacypool/legacypool_test.go @@ -1520,10 +1520,10 @@ func TestQueueAccountLimiting(t *testing.T) { account := crypto.PubkeyToAddress(key.PublicKey) testAddBalance(pool, account, big.NewInt(300000000000000)) - testTxPoolConfig.AccountQueue = 10 + accountQueue := uint64(10) // Keep queuing up transactions and make sure all above a limit are dropped - for i := uint64(1); i <= testTxPoolConfig.AccountQueue; i++ { + for i := uint64(1); i <= accountQueue; i++ { if err := pool.addRemoteSync(pricedTransaction(i, 100000, big.NewInt(300000000), key)); err != nil { t.Fatalf("tx %d: failed to add transaction: %v", i, err) } @@ -1531,18 +1531,18 @@ func TestQueueAccountLimiting(t *testing.T) { t.Errorf("tx %d: pending pool size mismatch: have %d, want %d", i, len(pool.pending), 0) } list, _ := pool.queue.get(account) - if i <= testTxPoolConfig.AccountQueue { + if i <= accountQueue { if list.Len() != int(i) { t.Errorf("tx %d: queue size mismatch: have %d, want %d", i, list.Len(), i) } } else { - if list.Len() != int(testTxPoolConfig.AccountQueue) { - t.Errorf("tx %d: queue limit mismatch: have %d, want %d", i, list.Len(), testTxPoolConfig.AccountQueue) + if list.Len() != int(accountQueue) { + t.Errorf("tx %d: queue limit mismatch: have %d, want %d", i, list.Len(), accountQueue) } } } - if pool.all.Count() != int(testTxPoolConfig.AccountQueue) { - t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), testTxPoolConfig.AccountQueue) + if pool.all.Count() != int(accountQueue) { + t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), accountQueue) } } @@ -1738,15 +1738,15 @@ func TestPendingLimiting(t *testing.T) { account := crypto.PubkeyToAddress(key.PublicKey) testAddBalance(pool, account, big.NewInt(400000000000000)) - testTxPoolConfig.AccountQueue = 10 + accountQueue := uint64(10) // Keep track of transaction events to ensure all executables get announced - events := make(chan core.NewTxsEvent, testTxPoolConfig.AccountQueue) + events := make(chan core.NewTxsEvent, accountQueue) sub := pool.txFeed.Subscribe(events) defer sub.Unsubscribe() // Keep queuing up transactions and make sure all above a limit are dropped - for i := uint64(0); i < testTxPoolConfig.AccountQueue; i++ { + for i := uint64(0); i < accountQueue; i++ { if err := pool.addRemoteSync(pricedTransaction(i, 100000, big.NewInt(300000000), key)); err != nil { t.Fatalf("tx %d: failed to add transaction: %v", i, err) } @@ -1757,10 +1757,10 @@ func TestPendingLimiting(t *testing.T) { t.Errorf("tx %d: queue size mismatch: have %d, want %d", i, len(pool.queue.addresses()), 0) } } - if pool.all.Count() != int(testTxPoolConfig.AccountQueue) { - t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), testTxPoolConfig.AccountQueue+5) + if pool.all.Count() != int(accountQueue) { + t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), accountQueue) } - if err := validateEvents(events, int(testTxPoolConfig.AccountQueue)); err != nil { + if err := validateEvents(events, int(accountQueue)); err != nil { t.Fatalf("event firing failed: %v", err) } if err := validatePoolInternals(pool); err != nil {