all: collate new transaction events together

This commit is contained in:
rjl493456442
2018-05-10 15:04:45 +08:00
committed by Péter Szilágyi
parent 6286c255f1
commit a2e43d28d0
19 changed files with 165 additions and 111 deletions

View File

@ -118,21 +118,26 @@ func validateTxPoolInternals(pool *TxPool) error {
// validateEvents checks that the correct number of transaction addition events
// were fired on the pool's event feed.
func validateEvents(events chan TxPreEvent, count int) error {
for i := 0; i < count; i++ {
func validateEvents(events chan TxsPreEvent, count int) error {
received := 0
for {
if received == count {
break
}
select {
case <-events:
case ev := <-events:
received += ev.Txs.Len()
case <-time.After(time.Second):
return fmt.Errorf("event #%d not fired", i)
return fmt.Errorf("event #%d not fired", received)
}
}
select {
case tx := <-events:
return fmt.Errorf("more than %d events fired: %v", count, tx.Tx)
case ev := <-events:
return fmt.Errorf("more than %d events fired: %v", count, ev.Txs)
case <-time.After(50 * time.Millisecond):
// This branch should be "default", but it's a data race between goroutines,
// reading the event channel and pushng into it, so better wait a bit ensuring
// reading the event channel and pushing into it, so better wait a bit ensuring
// really nothing gets injected.
}
return nil
@ -669,7 +674,7 @@ func TestTransactionGapFilling(t *testing.T) {
pool.currentState.AddBalance(account, big.NewInt(1000000))
// Keep track of transaction events to ensure all executables get announced
events := make(chan TxPreEvent, testTxPoolConfig.AccountQueue+5)
events := make(chan TxsPreEvent, testTxPoolConfig.AccountQueue+5)
sub := pool.txFeed.Subscribe(events)
defer sub.Unsubscribe()
@ -920,7 +925,7 @@ func TestTransactionPendingLimiting(t *testing.T) {
pool.currentState.AddBalance(account, big.NewInt(1000000))
// Keep track of transaction events to ensure all executables get announced
events := make(chan TxPreEvent, testTxPoolConfig.AccountQueue+5)
events := make(chan TxsPreEvent, testTxPoolConfig.AccountQueue+5)
sub := pool.txFeed.Subscribe(events)
defer sub.Unsubscribe()
@ -1140,7 +1145,7 @@ func TestTransactionPoolRepricing(t *testing.T) {
defer pool.Stop()
// Keep track of transaction events to ensure all executables get announced
events := make(chan TxPreEvent, 32)
events := make(chan TxsPreEvent, 32)
sub := pool.txFeed.Subscribe(events)
defer sub.Unsubscribe()
@ -1327,7 +1332,7 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
defer pool.Stop()
// Keep track of transaction events to ensure all executables get announced
events := make(chan TxPreEvent, 32)
events := make(chan TxsPreEvent, 32)
sub := pool.txFeed.Subscribe(events)
defer sub.Unsubscribe()
@ -1433,7 +1438,7 @@ func TestTransactionPoolStableUnderpricing(t *testing.T) {
defer pool.Stop()
// Keep track of transaction events to ensure all executables get announced
events := make(chan TxPreEvent, 32)
events := make(chan TxsPreEvent, 32)
sub := pool.txFeed.Subscribe(events)
defer sub.Unsubscribe()
@ -1495,7 +1500,7 @@ func TestTransactionReplacement(t *testing.T) {
defer pool.Stop()
// Keep track of transaction events to ensure all executables get announced
events := make(chan TxPreEvent, 32)
events := make(chan TxsPreEvent, 32)
sub := pool.txFeed.Subscribe(events)
defer sub.Unsubscribe()