From 88d0f24ce7a9f55b20c8175cd84020ff713b6f29 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Thu, 1 Sep 2016 21:13:06 +0200 Subject: [PATCH] Reduce lock timeout to zero --- src/cmds/restic/integration_test.go | 1 + src/restic/lock.go | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) 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{