From befecc9fdf5d1222cb1cd03d975e47be1e9d00d8 Mon Sep 17 00:00:00 2001 From: meowsbits <45600330+meowsbits@users.noreply.github.com> Date: Mon, 25 May 2020 11:01:03 -0500 Subject: [PATCH] consensus/ethash: fix flaky test by reading seal results (#21085) --- consensus/ethash/sealer_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/consensus/ethash/sealer_test.go b/consensus/ethash/sealer_test.go index 7f83def07..20ed2a418 100644 --- a/consensus/ethash/sealer_test.go +++ b/consensus/ethash/sealer_test.go @@ -97,16 +97,22 @@ func TestRemoteMultiNotify(t *testing.T) { ethash.config.Log = testlog.Logger(t, log.LvlWarn) defer ethash.Close() + // Provide a results reader. + // Otherwise the unread results will be logged asynchronously + // and this can happen after the test is finished, causing a panic. + results := make(chan *types.Block, cap(sink)) + // Stream a lot of work task and ensure all the notifications bubble out. for i := 0; i < cap(sink); i++ { header := &types.Header{Number: big.NewInt(int64(i)), Difficulty: big.NewInt(100)} block := types.NewBlockWithHeader(header) - ethash.Seal(nil, block, nil, nil) + ethash.Seal(nil, block, results, nil) } for i := 0; i < cap(sink); i++ { select { case <-sink: + <-results case <-time.After(10 * time.Second): t.Fatalf("notification %d timed out", i) }