miner: fix waitForMiningState precision

This helper function would return an affirmation
on the first positive match on a desired bool.

This was imprecise; it return false positives
by not waiting initially for an 'updated' value.

This fix causes TestMiner_2 to fail, which is
expected.

Signed-off-by: meows <b5c6@protonmail.com>
pull/21653/head
meows 4 years ago
parent 3b783dd1ed
commit 6d365c2851
No known key found for this signature in database
GPG Key ID: 5786AEA5C8D5A520
  1. 8
      miner/miner_test.go

@ -89,10 +89,10 @@ func TestMiner(t *testing.T) {
// Stop the downloader and wait for the update loop to run // Stop the downloader and wait for the update loop to run
mux.Post(downloader.DoneEvent{}) mux.Post(downloader.DoneEvent{})
waitForMiningState(t, miner, true) waitForMiningState(t, miner, true)
// Start the downloader, the mining state will not change because the update loop has exited
mux.Post(downloader.StartEvent{}) mux.Post(downloader.StartEvent{})
waitForMiningState(t, miner, true) waitForMiningState(t, miner, false)
// Stop the downloader, the mining state will not change
mux.Post(downloader.FailedEvent{}) mux.Post(downloader.FailedEvent{})
waitForMiningState(t, miner, true) waitForMiningState(t, miner, true)
} }
@ -158,10 +158,10 @@ func waitForMiningState(t *testing.T, m *Miner, mining bool) {
var state bool var state bool
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
time.Sleep(10 * time.Millisecond)
if state = m.Mining(); state == mining { if state = m.Mining(); state == mining {
return return
} }
time.Sleep(10 * time.Millisecond)
} }
t.Fatalf("Mining() == %t, want %t", state, mining) t.Fatalf("Mining() == %t, want %t", state, mining)
} }

Loading…
Cancel
Save