tests: fix usage of .reopen()

also:
add missing param to RemoteRepositoryTestCase.open method, but ignore it.
This commit is contained in:
Thomas Waldmann 2023-05-29 17:30:09 +02:00
parent 48c7879887
commit e2ea5cf164
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
1 changed files with 29 additions and 40 deletions

View File

@ -97,13 +97,12 @@ class RepositoryTestCase(RepositoryTestCaseBase):
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 @@ class RepositoryTestCase(RepositoryTestCaseBase):
# 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 @@ class RepositoryTestCase(RepositoryTestCaseBase):
# 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 @@ class LocalRepositoryTestCase(RepositoryTestCaseBase):
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 @@ class RepositoryCommitTestCase(RepositoryTestCaseBase):
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 @@ class RepositoryCommitTestCase(RepositoryTestCaseBase):
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 @@ class RepositoryHintsTestCase(RepositoryTestCaseBase):
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
)