ethash: fix flaky test by reading results from ethash Sealer

Fixes https://github.com/etclabscore/core-geth/issues/97

Signed-off-by: meows <b5c6@protonmail.com>
This commit is contained in:
meows 2020-05-14 10:12:56 -05:00
parent 3666da8a4b
commit feecb37e6b
No known key found for this signature in database
GPG key ID: 5786AEA5C8D5A520

View file

@ -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)
}