diff --git a/src/cmds/restic/integration_test.go b/src/cmds/restic/integration_test.go index e0e881301..3a3c53e6a 100644 --- a/src/cmds/restic/integration_test.go +++ b/src/cmds/restic/integration_test.go @@ -43,6 +43,7 @@ func parseIDsFromReader(t testing.TB, rd io.Reader) restic.IDs { func cmdInit(t testing.TB, global GlobalOptions) { repository.TestUseLowSecurityKDFParameters(t) + restic.TestSetLockTimeout(t, 0) cmd := &CmdInit{global: &global} OK(t, cmd.Execute(nil)) diff --git a/src/restic/lock.go b/src/restic/lock.go index 9f181106a..2cb0a1134 100644 --- a/src/restic/lock.go +++ b/src/restic/lock.go @@ -7,6 +7,7 @@ import ( "os/user" "sync" "syscall" + "testing" "time" "github.com/pkg/errors" @@ -68,7 +69,13 @@ func NewExclusiveLock(repo Repository) (*Lock, error) { return newLock(repo, true) } -const waitBeforeLockCheck = 200 * time.Millisecond +var waitBeforeLockCheck = 200 * time.Millisecond + +// TestSetLockTimeout can be used to reduce the lock wait timeout for tests. +func TestSetLockTimeout(t testing.TB, d time.Duration) { + t.Logf("setting lock timeout to %v", d) + waitBeforeLockCheck = d +} func newLock(repo Repository, excl bool) (*Lock, error) { lock := &Lock{