mirror of
https://github.com/restic/restic.git
synced 2024-08-30 13:46:03 +02:00
lock: fix flaky TestLockFailedRefresh
The comparison of the current time and the last lock refresh were using seconds represented as integers. As the test only waits for up to one second, the associated number truncation can cause the test to take longer than once second and thus to fail. Switch to nanoseconds to avoid this problem. This also slightly speeds up the test.
This commit is contained in:
parent
258b487d8f
commit
99547518cd
1 changed files with 2 additions and 2 deletions
|
@ -121,7 +121,7 @@ func refreshLocks(ctx context.Context, lock *restic.Lock, lockInfo *lockContext,
|
||||||
func monitorLockRefresh(ctx context.Context, lock *restic.Lock, lockInfo *lockContext, refreshed <-chan struct{}) {
|
func monitorLockRefresh(ctx context.Context, lock *restic.Lock, lockInfo *lockContext, refreshed <-chan struct{}) {
|
||||||
// time.Now() might use a monotonic timer which is paused during standby
|
// time.Now() might use a monotonic timer which is paused during standby
|
||||||
// convert to unix time to ensure we compare real time values
|
// convert to unix time to ensure we compare real time values
|
||||||
lastRefresh := time.Now().Unix()
|
lastRefresh := time.Now().UnixNano()
|
||||||
pollDuration := 1 * time.Second
|
pollDuration := 1 * time.Second
|
||||||
if refreshInterval < pollDuration {
|
if refreshInterval < pollDuration {
|
||||||
// require for TestLockFailedRefresh
|
// require for TestLockFailedRefresh
|
||||||
|
@ -145,7 +145,7 @@ func monitorLockRefresh(ctx context.Context, lock *restic.Lock, lockInfo *lockCo
|
||||||
case <-refreshed:
|
case <-refreshed:
|
||||||
lastRefresh = time.Now().Unix()
|
lastRefresh = time.Now().Unix()
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
if float64(time.Now().Unix()-lastRefresh) < refreshabilityTimeout.Seconds() {
|
if time.Now().UnixNano()-lastRefresh < refreshabilityTimeout.Nanoseconds() {
|
||||||
// restart timer
|
// restart timer
|
||||||
timer.Reset(pollDuration)
|
timer.Reset(pollDuration)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue