Merge pull request #7141 from RayyanAnsari/fix-repository-tests

Fix repository tests on Windows
This commit is contained in:
TW 2022-11-16 18:43:48 +01:00 committed by GitHub
commit 57c9f6193a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 8 deletions

View File

@ -128,6 +128,7 @@ class IntegrityCheckedFile(FileLikeWrapper):
self.writing = write
mode = "wb" if write else "rb"
self.file_fd = override_fd or open(path, mode)
self.file_opened = override_fd is None
self.digests = {}
hash_cls = XXH64FileHashingWrapper
@ -190,9 +191,14 @@ class IntegrityCheckedFile(FileLikeWrapper):
def __exit__(self, exc_type, exc_val, exc_tb):
exception = exc_type is not None
if not exception:
self.hash_part("final", is_final=True)
self.hasher.__exit__(exc_type, exc_val, exc_tb)
try:
if not exception:
self.hash_part("final", is_final=True)
self.hasher.__exit__(exc_type, exc_val, exc_tb)
finally:
if self.file_opened:
self.file_fd.close()
if exception:
return
if self.writing:

View File

@ -636,7 +636,7 @@ class Repository:
os.fsync(fd.fileno())
def rename_tmp(file):
os.rename(file + ".tmp", file)
os.replace(file + ".tmp", file)
hints = {
"version": 2,
@ -1448,13 +1448,12 @@ class LoggedIO:
def cleanup(self, transaction_id):
"""Delete segment files left by aborted transactions"""
self.close_segment()
self.segment = transaction_id + 1
count = 0
for segment, filename in self.segment_iterator(reverse=True):
if segment > transaction_id:
if segment in self.fds:
del self.fds[segment]
safe_unlink(filename)
self.delete_segment(segment)
count += 1
else:
break

View File

@ -844,7 +844,7 @@ class RepositoryCheckTestCase(RepositoryTestCaseBase):
fd.write(b"BOOM")
def delete_segment(self, segment):
os.unlink(os.path.join(self.tmppath, "repository", "data", "0", str(segment)))
self.repository.io.delete_segment(segment)
def delete_index(self):
os.unlink(os.path.join(self.tmppath, "repository", f"index.{self.get_head()}"))
@ -1138,6 +1138,14 @@ class RemoteRepositoryCheckTestCase(RepositoryCheckTestCase):
# skip this test, we can't mock-patch a Repository class in another process!
pass
def test_repair_missing_commit_segment(self):
# skip this test, files in RemoteRepository cannot be deleted
pass
def test_repair_missing_segment(self):
# skip this test, files in RemoteRepository cannot be deleted
pass
class RemoteLoggerTestCase(BaseTestCase):
def setUp(self):