Skip to content

Commit 6cb9795

Browse files
authored
test(core/txpool/legacypool): drop shared config writes from parallel tests (#2517)
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.
1 parent 1bc0167 commit 6cb9795

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

core/txpool/legacypool/legacypool_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,29 +1936,29 @@ func TestQueueAccountLimiting(t *testing.T) {
19361936

19371937
account := crypto.PubkeyToAddress(key.PublicKey)
19381938
testAddBalance(pool, account, big.NewInt(300000000000000))
1939-
testTxPoolConfig.AccountQueue = 10
1939+
accountQueue := uint64(10)
19401940

19411941
// Keep queuing up transactions and make sure all above a limit are dropped
1942-
for i := uint64(1); i <= testTxPoolConfig.AccountQueue; i++ {
1942+
for i := uint64(1); i <= accountQueue; i++ {
19431943
if err := pool.addRemoteSync(pricedTransaction(i, 100000, big.NewInt(300000000), key)); err != nil {
19441944
t.Fatalf("tx %d: failed to add transaction: %v", i, err)
19451945
}
19461946
if len(pool.pending) != 0 {
19471947
t.Errorf("tx %d: pending pool size mismatch: have %d, want %d", i, len(pool.pending), 0)
19481948
}
19491949
list, _ := pool.queue.get(account)
1950-
if i <= testTxPoolConfig.AccountQueue {
1950+
if i <= accountQueue {
19511951
if list.Len() != int(i) {
19521952
t.Errorf("tx %d: queue size mismatch: have %d, want %d", i, list.Len(), i)
19531953
}
19541954
} else {
1955-
if list.Len() != int(testTxPoolConfig.AccountQueue) {
1956-
t.Errorf("tx %d: queue limit mismatch: have %d, want %d", i, list.Len(), testTxPoolConfig.AccountQueue)
1955+
if list.Len() != int(accountQueue) {
1956+
t.Errorf("tx %d: queue limit mismatch: have %d, want %d", i, list.Len(), accountQueue)
19571957
}
19581958
}
19591959
}
1960-
if pool.all.Count() != int(testTxPoolConfig.AccountQueue) {
1961-
t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), testTxPoolConfig.AccountQueue)
1960+
if pool.all.Count() != int(accountQueue) {
1961+
t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), accountQueue)
19621962
}
19631963
}
19641964

@@ -2154,15 +2154,15 @@ func TestPendingLimiting(t *testing.T) {
21542154

21552155
account := crypto.PubkeyToAddress(key.PublicKey)
21562156
testAddBalance(pool, account, big.NewInt(400000000000000))
2157-
testTxPoolConfig.AccountQueue = 10
2157+
accountQueue := uint64(10)
21582158

21592159
// Keep track of transaction events to ensure all executables get announced
2160-
events := make(chan core.NewTxsEvent, testTxPoolConfig.AccountQueue)
2160+
events := make(chan core.NewTxsEvent, accountQueue)
21612161
sub := pool.txFeed.Subscribe(events)
21622162
defer sub.Unsubscribe()
21632163

21642164
// Keep queuing up transactions and make sure all above a limit are dropped
2165-
for i := uint64(0); i < testTxPoolConfig.AccountQueue; i++ {
2165+
for i := uint64(0); i < accountQueue; i++ {
21662166
if err := pool.addRemoteSync(pricedTransaction(i, 100000, big.NewInt(300000000), key)); err != nil {
21672167
t.Fatalf("tx %d: failed to add transaction: %v", i, err)
21682168
}
@@ -2173,10 +2173,10 @@ func TestPendingLimiting(t *testing.T) {
21732173
t.Errorf("tx %d: queue size mismatch: have %d, want %d", i, len(pool.queue.addresses()), 0)
21742174
}
21752175
}
2176-
if pool.all.Count() != int(testTxPoolConfig.AccountQueue) {
2177-
t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), testTxPoolConfig.AccountQueue+5)
2176+
if pool.all.Count() != int(accountQueue) {
2177+
t.Errorf("total transaction mismatch: have %d, want %d", pool.all.Count(), accountQueue)
21782178
}
2179-
if err := validateEvents(events, int(testTxPoolConfig.AccountQueue)); err != nil {
2179+
if err := validateEvents(events, int(accountQueue)); err != nil {
21802180
t.Fatalf("event firing failed: %v", err)
21812181
}
21822182
if err := validatePoolInternals(pool); err != nil {

0 commit comments

Comments
 (0)