mirror of
https://github.com/restic/restic.git
synced 2024-12-24 00:37:28 +00:00
Merge pull request #3990 from MichaelEischer/lock-refresh-test
lock: add test to check that refreshing works
This commit is contained in:
commit
47e05080a9
1 changed files with 24 additions and 0 deletions
|
@ -128,3 +128,27 @@ func TestLockFailedRefresh(t *testing.T) {
|
||||||
// unlockRepo should not crash
|
// unlockRepo should not crash
|
||||||
unlockRepo(lock)
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue