Przeglądaj źródła

repo: add test case for uncommitted garbage segment files

(cherry picked from commit 4a4c8884ee50de5a9f02e542f6813ca5c25e3181)
Thomas Waldmann 7 lat temu
rodzic
commit
2a58fe4266
1 zmienionych plików z 17 dodań i 0 usunięć
  1. 17 0
      src/borg/testsuite/repository.py

+ 17 - 0
src/borg/testsuite/repository.py

@@ -210,6 +210,23 @@ class LocalRepositoryTestCase(RepositoryTestCaseBase):
         self.repository.commit()
         assert 0 not in [segment for segment, _ in self.repository.io.segment_iterator()]
 
+    def test_uncommitted_garbage(self):
+        # uncommitted garbage should be no problem, it is cleaned up automatically.
+        # we just have to be careful with invalidation of cached FDs in LoggedIO.
+        self.repository.put(H(0), b'foo')
+        self.repository.commit()
+        # write some crap to a uncommitted segment file
+        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()
+        # usually, opening the repo and starting a transaction should trigger a cleanup.
+        self.repository = self.open()
+        with self.repository:
+            self.repository.put(H(0), b'bar')  # this may trigger compact_segments()
+            self.repository.commit()
+        # the point here is that nothing blows up with an exception.
+
 
 class RepositoryCommitTestCase(RepositoryTestCaseBase):