restic: cleanup lock test

This commit is contained in:
Michael Eischer 2023-07-09 15:35:37 +02:00
parent 24c8a33da9
commit d4bf7a3cb1

View file

@ -253,15 +253,10 @@ func TestRemoveAllLocks(t *testing.T) {
3, processed)
}
func TestLockRefresh(t *testing.T) {
repo := repository.TestRepository(t)
lock, err := restic.NewLock(context.TODO(), repo)
rtest.OK(t, err)
time0 := lock.Time
func checkSingleLock(t *testing.T, repo restic.Repository) restic.ID {
t.Helper()
var lockID *restic.ID
err = repo.List(context.TODO(), restic.LockFile, func(id restic.ID, size int64) error {
err := repo.List(context.TODO(), restic.LockFile, func(id restic.ID, size int64) error {
if lockID != nil {
t.Error("more than one lock found")
}
@ -271,25 +266,30 @@ func TestLockRefresh(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if lockID == nil {
t.Fatal("no lock found")
}
return *lockID
}
func TestLockRefresh(t *testing.T) {
repo := repository.TestRepository(t)
restic.TestSetLockTimeout(t, 5*time.Millisecond)
lock, err := restic.NewLock(context.TODO(), repo)
rtest.OK(t, err)
time0 := lock.Time
lockID := checkSingleLock(t, repo)
time.Sleep(time.Millisecond)
rtest.OK(t, lock.Refresh(context.TODO()))
var lockID2 *restic.ID
err = repo.List(context.TODO(), restic.LockFile, func(id restic.ID, size int64) error {
if lockID2 != nil {
t.Error("more than one lock found")
}
lockID2 = &id
return nil
})
if err != nil {
t.Fatal(err)
}
lockID2 := checkSingleLock(t, repo)
rtest.Assert(t, !lockID.Equal(*lockID2),
rtest.Assert(t, !lockID.Equal(lockID2),
"expected a new ID after lock refresh, got the same")
lock2, err := restic.LoadLock(context.TODO(), repo, *lockID2)
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")