"""
The reason for the failure is that the test relies on the scheduler.
There are two goroutines in play here.
When the test works, this happens:
txnpruner: receives on timer channe
txnpruner: calls MaybePruneTransaction, which sends on the test channel
test: receives on test channel
test: set t0
txnpruner: reset timer to 10ms
txnpruner: receives on timer channel at t0+10ms+something small
txnpruner: calls MaybePruneTransaction, which sends on the test channel
test: receives on test channel
test: set t1
test: t1 >= t0 + 10ms, all ok
But this can happen instead:
txnpruner: receives on timer channe
txnpruner: calls MaybePruneTransaction, which sends on the test channel
test: receives on test channel
txnpruner: reset timer to 10ms
test: set t0
txnpruner: receives on timer channel at t0+10ms+something small
txnpruner: calls MaybePruneTransaction, which sends on the test channel
test: receives on test channel
test: set t1
test: t1 < t0 + 10ms, fail
That is, there's nothing stopping the timer from resetting before the
test has decided on what time the previous event was set.
To fix this, the time should be set deterministically before the
code can continue running (for example by using a reply channel
or changing the test mock to send the time on the channel)
"""
From bug 1618560 see Roger's reasoning:
"""
The reason for the failure is that the test relies on the scheduler.
There are two goroutines in play here.
When the test works, this happens:
txnpruner: receives on timer channe action, which sends on the test channel action, which sends on the test channel
txnpruner: calls MaybePruneTrans
test: receives on test channel
test: set t0
txnpruner: reset timer to 10ms
txnpruner: receives on timer channel at t0+10ms+something small
txnpruner: calls MaybePruneTrans
test: receives on test channel
test: set t1
test: t1 >= t0 + 10ms, all ok
But this can happen instead:
txnpruner: receives on timer channe action, which sends on the test channel action, which sends on the test channel
txnpruner: calls MaybePruneTrans
test: receives on test channel
txnpruner: reset timer to 10ms
test: set t0
txnpruner: receives on timer channel at t0+10ms+something small
txnpruner: calls MaybePruneTrans
test: receives on test channel
test: set t1
test: t1 < t0 + 10ms, fail
That is, there's nothing stopping the timer from resetting before the
test has decided on what time the previous event was set.
To fix this, the time should be set deterministically before the
code can continue running (for example by using a reply channel
or changing the test mock to send the time on the channel)
"""