forked from TrueCloudLab/restic
restic: cleanup lock test
This commit is contained in:
parent
24c8a33da9
commit
d4bf7a3cb1
1 changed files with 21 additions and 21 deletions
|
@ -253,15 +253,10 @@ func TestRemoveAllLocks(t *testing.T) {
|
||||||
3, processed)
|
3, processed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLockRefresh(t *testing.T) {
|
func checkSingleLock(t *testing.T, repo restic.Repository) restic.ID {
|
||||||
repo := repository.TestRepository(t)
|
t.Helper()
|
||||||
|
|
||||||
lock, err := restic.NewLock(context.TODO(), repo)
|
|
||||||
rtest.OK(t, err)
|
|
||||||
time0 := lock.Time
|
|
||||||
|
|
||||||
var lockID *restic.ID
|
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 {
|
if lockID != nil {
|
||||||
t.Error("more than one lock found")
|
t.Error("more than one lock found")
|
||||||
}
|
}
|
||||||
|
@ -271,25 +266,30 @@ func TestLockRefresh(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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)
|
time.Sleep(time.Millisecond)
|
||||||
rtest.OK(t, lock.Refresh(context.TODO()))
|
rtest.OK(t, lock.Refresh(context.TODO()))
|
||||||
|
|
||||||
var lockID2 *restic.ID
|
lockID2 := checkSingleLock(t, repo)
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
rtest.Assert(t, !lockID.Equal(*lockID2),
|
rtest.Assert(t, !lockID.Equal(lockID2),
|
||||||
"expected a new ID after lock refresh, got the same")
|
"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.OK(t, err)
|
||||||
rtest.Assert(t, lock2.Time.After(time0),
|
rtest.Assert(t, lock2.Time.After(time0),
|
||||||
"expected a later timestamp after lock refresh")
|
"expected a later timestamp after lock refresh")
|
||||||
|
|
Loading…
Reference in a new issue