Skip to content

Commit

Permalink
Fix racey bloom access and replace time.Sleep with require.Eventually
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored and darioush committed Jan 22, 2024
1 parent acd3f4a commit 9b4808a
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions plugin/evm/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ func TestGossipSubscribe(t *testing.T) {
gossipTxPool.bloom, err = gossip.NewBloomFilter(1, 0.01, 0.0000000000000001) // maxCount =1
require.NoError(err)
ctx, cancel := context.WithCancel(context.TODO())
go func() {
gossipTxPool.Subscribe(ctx)
}()
defer cancel()
go gossipTxPool.Subscribe(ctx)

// create eth txs
ethTxs := getValidEthTxs(key, 10, big.NewInt(226*params.GWei))
Expand All @@ -68,12 +67,23 @@ func TestGossipSubscribe(t *testing.T) {
for _, err := range errs {
require.NoError(err, "failed adding subnet-evm tx to remote mempool")
}
time.Sleep(1 * time.Second)
cancel()
for i, tx := range ethTxs {
gossipable := &GossipEthTx{Tx: tx}
require.Truef(gossipTxPool.bloom.Has(gossipable), "expected tx to be in bloom filter: index %d", i)
}

require.Eventually(
func() bool {
gossipTxPool.lock.RLock()
defer gossipTxPool.lock.RUnlock()

for _, tx := range ethTxs {
if !gossipTxPool.bloom.Has(&GossipEthTx{Tx: tx}) {
return false
}
}
return true
},
10*time.Second,
10*time.Millisecond,
"expected all transactions to eventually be in the bloom filter",
)
}

func setupPoolWithConfig(t *testing.T, config *params.ChainConfig, fundedAddress common.Address) *txpool.TxPool {
Expand Down

0 comments on commit 9b4808a

Please sign in to comment.