Update Lock.Time in lock.Refresh()

This commit is contained in:
Eric Hamilton 2019-09-04 11:38:35 -07:00
parent 604b18aa74
commit 1596d06f8e
2 changed files with 7 additions and 0 deletions

View File

@ -221,6 +221,7 @@ func (l *Lock) Stale() bool {
// timestamp. Afterwards the old lock is removed.
func (l *Lock) Refresh(ctx context.Context) error {
debug.Log("refreshing lock %v", l.lockID)
l.Time = time.Now()
id, err := l.createLock(ctx)
if err != nil {
return err

View File

@ -225,6 +225,7 @@ func TestLockRefresh(t *testing.T) {
lock, err := restic.NewLock(context.TODO(), repo)
rtest.OK(t, err)
time0 := lock.Time
var lockID *restic.ID
err = repo.List(context.TODO(), restic.LockFile, func(id restic.ID, size int64) error {
@ -238,6 +239,7 @@ func TestLockRefresh(t *testing.T) {
t.Fatal(err)
}
time.Sleep(time.Millisecond)
rtest.OK(t, lock.Refresh(context.TODO()))
var lockID2 *restic.ID
@ -254,5 +256,9 @@ func TestLockRefresh(t *testing.T) {
rtest.Assert(t, !lockID.Equal(*lockID2),
"expected a new ID after lock refresh, got the same")
lock2, err := restic.LoadLock(context.TODO(), repo, *lockID2)
rtest.OK(t, err)
rtest.Assert(t, lock2.Time.After(time0),
"expected a later timestamp after lock refresh")
rtest.OK(t, lock.Unlock())
}