[Zope3-checkins] CVS: ZODB/src/ZODB/tests - testRecover.py:1.8
Tim Peters
tim.one at comcast.net
Mon May 3 14:44:33 EDT 2004
Update of /cvs-repository/ZODB/src/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv9111/src/ZODB/tests
Modified Files:
testRecover.py
Log Message:
Collector #1307: fsrecover.py broken on HEAD.
fsrecover.py: the call to restore() was still using .serial, which no
longer exists. Changed to use .tid.
testRecover.py: the tests here passed despite that fsrecover wasn't
working at all. Changed RecoverTest.recover() to eliminate its unused
arguments, and to return all the output fsrecover.recover() produces (the
output was being thrown away, unlooked at). Added new testNoDamage(),
which feeds recovery a healthy .fs, and then looks at the output of
recovery, to verify that no errors were reported and no bytes were
removed by recovery. Changed all the other tests to stop passing unused
arguments to RecoverTest.recover(), and to verify that error output was
produced by recovery.
XXX I'm not sure that every call to RecoverTest.recover() will actually
XXX produce an error in fsrecover.recover(), so we may get some spurious
XXX test failures here. I'll keep my open for those. (The kinds of
XXX damage tested are randomized, so one run doesn't prove anything.)
=== ZODB/src/ZODB/tests/testRecover.py 1.7 => 1.8 ===
--- ZODB/src/ZODB/tests/testRecover.py:1.7 Fri Apr 16 11:58:11 2004
+++ ZODB/src/ZODB/tests/testRecover.py Mon May 3 14:44:32 2004
@@ -76,22 +76,38 @@
ITERATIONS = 5
- def recover(self, source, dest):
- orig = sys.stdout
+ # Run recovery, from self.path to self.dest. Return whatever
+ # recovery printed to stdout, as a string.
+ def recover(self):
+ orig_stdout = sys.stdout
+ faux_stdout = StringIO.StringIO()
try:
- sys.stdout = StringIO.StringIO()
+ sys.stdout = faux_stdout
try:
recover(self.path, self.dest,
verbose=0, partial=1, force=0, pack=1)
except SystemExit:
raise RuntimeError, "recover tried to exit"
finally:
- sys.stdout = orig
+ sys.stdout = orig_stdout
+ return faux_stdout.getvalue()
+
+ # Caution: because recovery is robust against many kinds of damage,
+ # it's almost impossible for a call to self.recover() to raise an
+ # exception. As a result, these tests may pass even if fsrecover.py
+ # is broken badly. testNoDamage() tries to ensure that at least
+ # recovery doesn't produce any error msgs if the input .fs is in
+ # fact not damaged.
+ def testNoDamage(self):
+ output = self.recover()
+ self.assert_('error' not in output, output)
+ self.assert_('0 bytes removed during recovery' in output, output)
def testOneBlock(self):
for i in range(self.ITERATIONS):
self.damage(1, 1024)
- self.recover(self.path, self.dest)
+ output = self.recover()
+ self.assert_('error' in output)
self.recovered = FileStorage(self.dest)
self.recovered.close()
os.remove(self.path)
@@ -100,7 +116,8 @@
def testFourBlocks(self):
for i in range(self.ITERATIONS):
self.damage(4, 512)
- self.recover(self.path, self.dest)
+ output = self.recover()
+ self.assert_('error' in output)
self.recovered = FileStorage(self.dest)
self.recovered.close()
os.remove(self.path)
@@ -109,7 +126,8 @@
def testBigBlock(self):
for i in range(self.ITERATIONS):
self.damage(1, 32 * 1024)
- self.recover(self.path, self.dest)
+ output = self.recover()
+ self.assert_('error' in output)
self.recovered = FileStorage(self.dest)
self.recovered.close()
os.remove(self.path)
@@ -134,7 +152,8 @@
f.seek(pos1 - 50)
f.write("\0" * 100)
f.close()
- self.recover(self.path, self.dest)
+ output = self.recover()
+ self.assert_('error' in output)
self.recovered = FileStorage(self.dest)
self.recovered.close()
os.remove(self.path)
@@ -145,7 +164,8 @@
f.seek(pos2 + 10)
f.write("\0" * 100)
f.close()
- self.recover(self.path, self.dest)
+ output = self.recover()
+ self.assert_('error' in output)
self.recovered = FileStorage(self.dest)
self.recovered.close()
More information about the Zope3-Checkins
mailing list