Fix flaky heartbeat test by ensuring time deadline is hit

Look into using util.IsTrueWithin(trueFunc func() bool, duration time.Duration) error

This method is more widely used in the testing code and will prevent an endless wait as a side benefit.