Skip to content

Commit befecc9

Browse files
authored
consensus/ethash: fix flaky test by reading seal results (#21085)
1 parent e868add commit befecc9

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎consensus/ethash/sealer_test.go‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,22 @@ func TestRemoteMultiNotify(t *testing.T) {
9797
ethash.config.Log = testlog.Logger(t, log.LvlWarn)
9898
defer ethash.Close()
9999

100+
// Provide a results reader.
101+
// Otherwise the unread results will be logged asynchronously
102+
// and this can happen after the test is finished, causing a panic.
103+
results := make(chan *types.Block, cap(sink))
104+
100105
// Stream a lot of work task and ensure all the notifications bubble out.
101106
for i := 0; i < cap(sink); i++ {
102107
header := &types.Header{Number: big.NewInt(int64(i)), Difficulty: big.NewInt(100)}
103108
block := types.NewBlockWithHeader(header)
104-
ethash.Seal(nil, block, nil, nil)
109+
ethash.Seal(nil, block, results, nil)
105110
}
106111

107112
for i := 0; i < cap(sink); i++ {
108113
select {
109114
case <-sink:
115+
<-results
110116
case <-time.After(10 * time.Second):
111117
t.Fatalf("notification %d timed out", i)
112118
}

0 commit comments

Comments
 (0)