From a509a0c463e3d2f93af281f212199105376edae3 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 6 Sep 2024 23:50:42 +0200 Subject: [PATCH] locking: no traceback on lock timeout (expected) --- src/borg/storelocking.py | 3 +-- src/borg/testsuite/archiver/lock_cmds.py | 2 +- src/borg/testsuite/storelocking.py | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/borg/storelocking.py b/src/borg/storelocking.py index 8f1979eb3..dc111f9c1 100644 --- a/src/borg/storelocking.py +++ b/src/borg/storelocking.py @@ -186,8 +186,7 @@ class Lock: self._delete_lock(key, ignore_not_found=True) # wait a random bit before retrying time.sleep(self.retry_delay_min + (self.retry_delay_max - self.retry_delay_min) * random.random()) - # timeout - raise LockFailed(str(self.store), "timeout") + raise LockTimeout(str(self.store)) def release(self): locks = self._find_locks(only_mine=True) diff --git a/src/borg/testsuite/archiver/lock_cmds.py b/src/borg/testsuite/archiver/lock_cmds.py index 8fce39bd9..9b7857f6b 100644 --- a/src/borg/testsuite/archiver/lock_cmds.py +++ b/src/borg/testsuite/archiver/lock_cmds.py @@ -37,7 +37,7 @@ def test_with_lock(tmp_path): out, err_out = p2.communicate() assert "second command" not in out # command2 is "locked out" assert "Failed to create/acquire the lock" in err_out - assert p2.returncode == 72 # LockTimeout: could not acquire the lock, p1 already has it + assert p2.returncode == 73 # LockTimeout: could not acquire the lock, p1 already has it out, err_out = p1.communicate() assert "first command" in out # command1 was executed and had the lock assert not err_out diff --git a/src/borg/testsuite/storelocking.py b/src/borg/testsuite/storelocking.py index b4586a6bf..4fbf0be34 100644 --- a/src/borg/testsuite/storelocking.py +++ b/src/borg/testsuite/storelocking.py @@ -4,7 +4,7 @@ import pytest from borgstore.store import Store -from ..storelocking import Lock, LockFailed, NotLocked +from ..storelocking import Lock, NotLocked, LockTimeout ID1 = "foo", 1, 1 ID2 = "bar", 2, 2 @@ -37,11 +37,11 @@ class TestLock: def test_exclusive_lock(self, lockstore): # there must not be 2 exclusive locks with Lock(lockstore, exclusive=True, id=ID1): - with pytest.raises(LockFailed): + with pytest.raises(LockTimeout): Lock(lockstore, exclusive=True, id=ID2).acquire() # acquiring an exclusive lock will time out if the non-exclusive does not go away with Lock(lockstore, exclusive=False, id=ID1): - with pytest.raises(LockFailed): + with pytest.raises(LockTimeout): Lock(lockstore, exclusive=True, id=ID2).acquire() def test_double_nonexclusive_lock_succeeds(self, lockstore):