From 1645c329979cd9b409c19dd76b6cf28cb499bfe0 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 3 Apr 2024 19:10:31 -0700 Subject: [PATCH] test: eth: deflake EthBlockHashesCorrect_MultiBlockTipset (#11808) Increase the chances of having multiple blocks at the same height by aligning block times across test miners. Also, make the block hash test faster. --- itests/eth_block_hash_test.go | 24 +++++++++++++++--------- itests/kit/blockminer.go | 7 ++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/itests/eth_block_hash_test.go b/itests/eth_block_hash_test.go index 8debefa492c..927b64fc599 100644 --- a/itests/eth_block_hash_test.go +++ b/itests/eth_block_hash_test.go @@ -26,30 +26,36 @@ import ( func TestEthBlockHashesCorrect_MultiBlockTipset(t *testing.T) { // miner is connected to the first node, and we want to observe the chain // from the second node. - blocktime := 250 * time.Millisecond + blocktime := 100 * time.Millisecond n1, m1, m2, ens := kit.EnsembleOneTwo(t, kit.MockProofs(), kit.ThroughRPC(), ) ens.InterconnectAll().BeginMining(blocktime) - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - n1.WaitTillChain(ctx, kit.HeightAtLeast(abi.ChainEpoch(5))) - defer cancel() + { + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + n1.WaitTillChain(ctx, kit.HeightAtLeast(abi.ChainEpoch(5))) + cancel() + } var n2 kit.TestFullNode ens.FullNode(&n2, kit.ThroughRPC()).Start().Connect(n2, n1) - // find the first tipset where all miners mined a block. - ctx, cancel = context.WithTimeout(context.Background(), 5*time.Minute) - n2.WaitTillChain(ctx, kit.BlocksMinedByAll(m1.ActorAddr, m2.ActorAddr)) - defer cancel() + { + // find the first tipset where all miners mined a block. + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) + n2.WaitTillChain(ctx, kit.BlocksMinedByAll(m1.ActorAddr, m2.ActorAddr)) + cancel() + } head, err := n2.ChainHead(context.Background()) require.NoError(t, err) + ctx := context.Background() + // let the chain run a little bit longer to minimise the chance of reorgs - n2.WaitTillChain(ctx, kit.HeightAtLeast(head.Height()+50)) + n2.WaitTillChain(ctx, kit.HeightAtLeast(head.Height()+10)) tsk := head.Key() for i := 1; i <= int(head.Height()); i++ { diff --git a/itests/kit/blockminer.go b/itests/kit/blockminer.go index bd527910d79..40d23a6cdf0 100644 --- a/itests/kit/blockminer.go +++ b/itests/kit/blockminer.go @@ -256,8 +256,6 @@ func (bm *BlockMiner) MineBlocksMustPost(ctx context.Context, blocktime time.Dur } func (bm *BlockMiner) MineBlocks(ctx context.Context, blocktime time.Duration) { - time.Sleep(time.Second) - // wrap context in a cancellable context. ctx, bm.cancel = context.WithCancel(ctx) @@ -278,8 +276,11 @@ func (bm *BlockMiner) MineBlocks(ctx context.Context, blocktime time.Duration) { default: } + now := time.Duration(time.Now().UnixNano()) + delay := blocktime - (now % blocktime) + select { - case <-time.After(blocktime): + case <-time.After(delay): case <-ctx.Done(): return }