From add699d2386714c85073d5cb1d7d82eaa5a4847c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 24 Aug 2021 11:05:51 -0700 Subject: [PATCH] fix: make sure we start the publish timer before recording the time Otherwise, our nice and deterministic test may keep repeatedly setting the time to _right_ before the timer fires. --- markets/storageadapter/dealpublisher.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/markets/storageadapter/dealpublisher.go b/markets/storageadapter/dealpublisher.go index 99f5980ee..f458e7a4f 100644 --- a/markets/storageadapter/dealpublisher.go +++ b/markets/storageadapter/dealpublisher.go @@ -228,11 +228,15 @@ func (p *DealPublisher) waitForMoreDeals() { // Set a timeout to wait for more deals to arrive log.Infof("waiting publish deals queue period of %s before publishing", p.publishPeriod) ctx, cancel := context.WithCancel(p.ctx) + + // Create the timer _before_ taking the current time so publishPeriod+timeout is always >= + // the actual timer timeout. + timer := build.Clock.Timer(p.publishPeriod) + p.publishPeriodStart = build.Clock.Now() p.cancelWaitForMoreDeals = cancel go func() { - timer := build.Clock.Timer(p.publishPeriod) select { case <-ctx.Done(): timer.Stop()