Skip to content

Commit

Permalink
ethash: fix flaky test by reading results from ethash Sealer
Browse files Browse the repository at this point in the history
Fixes #97

Signed-off-by: meows <[email protected]>
  • Loading branch information
meowsbits committed May 14, 2020
1 parent de01ccf commit 81820a2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion consensus/ethash/sealer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 81820a2

Please sign in to comment.