From 9b4808adfd1af0314828f7483ecfc23374ea81ba Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Mon, 22 Jan 2024 17:31:04 -0500 Subject: [PATCH] Fix racey bloom access and replace time.Sleep with require.Eventually --- plugin/evm/gossip_test.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/plugin/evm/gossip_test.go b/plugin/evm/gossip_test.go index dff56c03b1..a9f80355e8 100644 --- a/plugin/evm/gossip_test.go +++ b/plugin/evm/gossip_test.go @@ -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)) @@ -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 {