From 24267e9a9deab823f626b5c27278bb469f9c0ead Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 29 Oct 2022 11:26:00 +0200 Subject: [PATCH] lock: add test to check that refreshing works --- cmd/restic/lock_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/restic/lock_test.go b/cmd/restic/lock_test.go index 70e864448..faa608221 100644 --- a/cmd/restic/lock_test.go +++ b/cmd/restic/lock_test.go @@ -128,3 +128,27 @@ func TestLockFailedRefresh(t *testing.T) { // unlockRepo should not crash unlockRepo(lock) } + +func TestLockSuccessfulRefresh(t *testing.T) { + repo, cleanup, _ := openTestRepo(t, nil) + defer cleanup() + + // reduce locking intervals to be suitable for testing + ri, rt := refreshInterval, refreshabilityTimeout + refreshInterval = 20 * time.Millisecond + refreshabilityTimeout = 100 * time.Millisecond + defer func() { + refreshInterval, refreshabilityTimeout = ri, rt + }() + + lock, wrappedCtx := checkedLockRepo(context.Background(), t, repo) + + select { + case <-wrappedCtx.Done(): + t.Fatal("lock refresh failed") + case <-time.After(2 * refreshabilityTimeout): + // expected lock refresh to work + } + // unlockRepo should not crash + unlockRepo(lock) +}