mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-01 12:45:34 +00:00
tests: fix usage of .reopen()
also: add missing param to RemoteRepositoryTestCase.open method, but ignore it.
This commit is contained in:
parent
48c7879887
commit
e2ea5cf164
1 changed files with 29 additions and 40 deletions
|
@ -97,13 +97,12 @@ def test1(self):
|
|||
self.repository.delete(key50)
|
||||
self.assert_raises(Repository.ObjectNotFound, lambda: self.repository.get(key50))
|
||||
self.repository.commit(compact=False)
|
||||
self.repository.close()
|
||||
with self.open() as repository2:
|
||||
self.assert_raises(Repository.ObjectNotFound, lambda: repository2.get(key50))
|
||||
for x in range(100):
|
||||
if x == 50:
|
||||
continue
|
||||
self.assert_equal(pdchunk(repository2.get(H(x))), b"SOMEDATA")
|
||||
self.reopen()
|
||||
self.assert_raises(Repository.ObjectNotFound, lambda: self.repository.get(key50))
|
||||
for x in range(100):
|
||||
if x == 50:
|
||||
continue
|
||||
self.assert_equal(pdchunk(self.repository.get(H(x))), b"SOMEDATA")
|
||||
|
||||
def test2(self):
|
||||
"""Test multiple sequential transactions"""
|
||||
|
@ -158,17 +157,14 @@ def test_single_kind_transactions(self):
|
|||
# put
|
||||
self.repository.put(H(0), fchunk(b"foo"))
|
||||
self.repository.commit(compact=False)
|
||||
self.repository.close()
|
||||
self.reopen()
|
||||
# replace
|
||||
self.repository = self.open()
|
||||
with self.repository:
|
||||
self.repository.put(H(0), fchunk(b"bar"))
|
||||
self.repository.commit(compact=False)
|
||||
self.repository.put(H(0), fchunk(b"bar"))
|
||||
self.repository.commit(compact=False)
|
||||
self.reopen()
|
||||
# delete
|
||||
self.repository = self.open()
|
||||
with self.repository:
|
||||
self.repository.delete(H(0))
|
||||
self.repository.commit(compact=False)
|
||||
self.repository.delete(H(0))
|
||||
self.repository.commit(compact=False)
|
||||
|
||||
def test_list(self):
|
||||
for x in range(100):
|
||||
|
@ -275,14 +271,11 @@ def test_flags_persistence(self):
|
|||
# we do not set flags for H(0), so we can later check their default state.
|
||||
self.repository.flags(H(1), mask=0x00000007, value=0x00000006)
|
||||
self.repository.commit(compact=False)
|
||||
self.repository.close()
|
||||
|
||||
self.repository = self.open()
|
||||
with self.repository:
|
||||
# we query all flags to check if the initial flags were all zero and
|
||||
# only the ones we explicitly set to one are as expected.
|
||||
self.assert_equal(self.repository.flags(H(0), mask=0xFFFFFFFF), 0x00000000)
|
||||
self.assert_equal(self.repository.flags(H(1), mask=0xFFFFFFFF), 0x00000006)
|
||||
self.reopen()
|
||||
# we query all flags to check if the initial flags were all zero and
|
||||
# only the ones we explicitly set to one are as expected.
|
||||
self.assert_equal(self.repository.flags(H(0), mask=0xFFFFFFFF), 0x00000000)
|
||||
self.assert_equal(self.repository.flags(H(1), mask=0xFFFFFFFF), 0x00000006)
|
||||
|
||||
|
||||
class LocalRepositoryTestCase(RepositoryTestCaseBase):
|
||||
|
@ -336,12 +329,10 @@ def test_uncommitted_garbage(self):
|
|||
last_segment = self.repository.io.get_latest_segment()
|
||||
with open(self.repository.io.segment_filename(last_segment + 1), "wb") as f:
|
||||
f.write(MAGIC + b"crapcrapcrap")
|
||||
self.repository.close()
|
||||
self.reopen()
|
||||
# usually, opening the repo and starting a transaction should trigger a cleanup.
|
||||
self.repository = self.open()
|
||||
with self.repository:
|
||||
self.repository.put(H(0), fchunk(b"bar")) # this may trigger compact_segments()
|
||||
self.repository.commit(compact=True)
|
||||
self.repository.put(H(0), fchunk(b"bar")) # this may trigger compact_segments()
|
||||
self.repository.commit(compact=True)
|
||||
# the point here is that nothing blows up with an exception.
|
||||
|
||||
|
||||
|
@ -384,11 +375,10 @@ def test_replay_lock_upgrade_old(self):
|
|||
os.unlink(os.path.join(self.repository.path, name))
|
||||
with patch.object(Lock, "upgrade", side_effect=LockFailed) as upgrade:
|
||||
self.reopen(exclusive=None) # simulate old client that always does lock upgrades
|
||||
with self.repository:
|
||||
# the repo is only locked by a shared read lock, but to replay segments,
|
||||
# we need an exclusive write lock - check if the lock gets upgraded.
|
||||
self.assert_raises(LockFailed, lambda: len(self.repository))
|
||||
upgrade.assert_called_once_with()
|
||||
# the repo is only locked by a shared read lock, but to replay segments,
|
||||
# we need an exclusive write lock - check if the lock gets upgraded.
|
||||
self.assert_raises(LockFailed, lambda: len(self.repository))
|
||||
upgrade.assert_called_once_with()
|
||||
|
||||
def test_replay_lock_upgrade(self):
|
||||
self.add_keys()
|
||||
|
@ -397,11 +387,10 @@ def test_replay_lock_upgrade(self):
|
|||
os.unlink(os.path.join(self.repository.path, name))
|
||||
with patch.object(Lock, "upgrade", side_effect=LockFailed) as upgrade:
|
||||
self.reopen(exclusive=False) # current client usually does not do lock upgrade, except for replay
|
||||
with self.repository:
|
||||
# the repo is only locked by a shared read lock, but to replay segments,
|
||||
# we need an exclusive write lock - check if the lock gets upgraded.
|
||||
self.assert_raises(LockFailed, lambda: len(self.repository))
|
||||
upgrade.assert_called_once_with()
|
||||
# the repo is only locked by a shared read lock, but to replay segments,
|
||||
# we need an exclusive write lock - check if the lock gets upgraded.
|
||||
self.assert_raises(LockFailed, lambda: len(self.repository))
|
||||
upgrade.assert_called_once_with()
|
||||
|
||||
def test_crash_before_deleting_compacted_segments(self):
|
||||
self.add_keys()
|
||||
|
@ -931,7 +920,7 @@ def test_hints_behaviour(self):
|
|||
class RemoteRepositoryTestCase(RepositoryTestCase):
|
||||
repository = None # type: RemoteRepository
|
||||
|
||||
def open(self, create=False):
|
||||
def open(self, create=False, exclusive=UNSPECIFIED):
|
||||
return RemoteRepository(
|
||||
Location("ssh://__testsuite__" + os.path.join(self.tmppath, "repository")), exclusive=True, create=create
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue