From: Brian Warner Date: Tue, 26 Jun 2007 22:55:00 +0000 (-0700) Subject: dump_uri_extension: improve test coverage of runner.py X-Git-Tag: allmydata-tahoe-0.4.0~27 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/reliability?a=commitdiff_plain;h=de24d3cd94f325b700de7a64bc5b21a7f4ad7d5f;p=tahoe-lafs%2Ftahoe-lafs.git dump_uri_extension: improve test coverage of runner.py --- diff --git a/src/allmydata/scripts/runner.py b/src/allmydata/scripts/runner.py index 2f0ac6a0..b573dcc5 100644 --- a/src/allmydata/scripts/runner.py +++ b/src/allmydata/scripts/runner.py @@ -325,7 +325,7 @@ def stop(basedir, config): print "never saw process go away" return 1 -def dump_uri_extension(config): +def dump_uri_extension(config, output=sys.stdout): from allmydata import uri filename = config['filename'] @@ -338,23 +338,23 @@ def dump_uri_extension(config): "share_root_hash") for k in keys1: if k in unpacked: - print "%19s: %s" % (k, unpacked[k]) - print + print >>output, "%19s: %s" % (k, unpacked[k]) + print >>output for k in keys2: if k in unpacked: - print "%19s: %s" % (k, unpacked[k]) - print + print >>output, "%19s: %s" % (k, unpacked[k]) + print >>output for k in keys3: if k in unpacked: - print "%19s: %s" % (k, unpacked[k]) + print >>output, "%19s: %s" % (k, unpacked[k]) leftover = set(unpacked.keys()) - set(keys1 + keys2 + keys3) if leftover: - print + print >>output for k in sorted(leftover): - print "%s: %s" % (k, unpacked[k]) + print >>output, "%s: %s" % (k, unpacked[k]) - print + print >>output return 0 def dump_root_dirnode(basedir, config, output=sys.stdout): diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index af1bda46..509b7f46 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -1,11 +1,13 @@ import os +from cStringIO import StringIO from twisted.trial import unittest from twisted.internet import defer, reactor from twisted.application import service from allmydata import client, uri, download, upload from allmydata.introducer_and_vdrive import IntroducerAndVdrive from allmydata.util import idlib, fileutil, testutil +from allmydata.scripts import runner from foolscap.eventual import flushEventualQueue from twisted.python import log from twisted.python.failure import Failure @@ -259,6 +261,7 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase): self.failUnlessEqual(data, DATA) d.addCallback(_get_done) d.addCallback(self._test_web) + d.addCallback(self._test_runner) return d test_vdrive.timeout = 1100 @@ -360,3 +363,38 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase): return d + def _test_runner(self, res): + # exercise some of the diagnostic tools in runner.py + + # find a uri_extension file + for (dirpath, dirnames, filenames) in os.walk(self.basedir): + if "uri_extension" in filenames: + break + else: + self.fail("unable to find any uri_extension files in %s" + % self.basedir) + log.msg("test_system.SystemTest._test_runner using %s" % dirpath) + + filename = os.path.join(dirpath, "uri_extension") + s = StringIO() + rc = runner.dump_uri_extension({'filename': filename}, s) + output = s.getvalue() + self.failUnlessEqual(rc, 0) + + # we only upload a single file, so we can assert some things about + # its size and shares + self.failUnless("size: %d\n" % len(self.data) in output) + self.failUnless("num_segments: 1\n" in output) + # segment_size is always a multiple of needed_shares + self.failUnless("segment_size: 50\n" in output) + self.failUnless("total_shares: 100\n" in output) + # keys which are supposed to be present + for key in ("size", "num_segments", "segment_size", + "needed_shares", "total_shares", + "codec_name", "codec_params", "tail_codec_params", + "plaintext_hash", "plaintext_root_hash", + "crypttext_hash", "crypttext_root_hash", + "share_root_hash", + ): + self.failUnless("%s: " % key in output, key) +