From: Brian Warner Date: Mon, 6 Oct 2008 22:50:37 +0000 (-0700) Subject: test_system: add test coverage for immutable download.ConsumerAdapter, remove debug... X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/vdrive?a=commitdiff_plain;h=d90a3ed7f8a7d721fe59a2141529d81636a23fde;p=tahoe-lafs%2Ftahoe-lafs.git test_system: add test coverage for immutable download.ConsumerAdapter, remove debug messages --- diff --git a/src/allmydata/immutable/download.py b/src/allmydata/immutable/download.py index f8d2a00a..80b9ce65 100644 --- a/src/allmydata/immutable/download.py +++ b/src/allmydata/immutable/download.py @@ -1046,13 +1046,13 @@ class ConsumerAdapter: self._when_finished = observer.OneShotObserverList() def when_finished(self): + # I think this is unused, along with self._when_finished . But I need + # to trace the error paths to be sure. return self._when_finished.when_fired() def registerProducer(self, producer, streaming): - print "REG" self._consumer.registerProducer(producer, streaming) def unregisterProducer(self): - print "UNREG" self._consumer.unregisterProducer() def open(self, size): diff --git a/src/allmydata/immutable/filenode.py b/src/allmydata/immutable/filenode.py index a1a66128..93ba4047 100644 --- a/src/allmydata/immutable/filenode.py +++ b/src/allmydata/immutable/filenode.py @@ -92,10 +92,8 @@ class FileNode(ImmutableFileNode): class LiteralProducer: implements(IPushProducer) def resumeProducing(self): - print "LIT RESUME" pass def stopProducing(self): - print "LIT STOP" pass class LiteralFileNode(ImmutableFileNode): diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index 89ec26ee..ad614c38 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -1,10 +1,12 @@ from base64 import b32encode import os, sys, time, re, simplejson, urllib from cStringIO import StringIO +from zope.interface import implements from twisted.trial import unittest from twisted.internet import defer from twisted.internet import threads # CLI tests use deferToThread from twisted.internet.error import ConnectionDone, ConnectionLost +from twisted.internet.interfaces import IConsumer, IPushProducer import allmydata from allmydata import uri, storage, offloaded from allmydata.immutable import download, upload, filenode @@ -41,6 +43,21 @@ class CountingDataUploadable(upload.Data): self.interrupt_after_d.callback(self) return upload.Data.read(self, length) +class GrabEverythingConsumer: + implements(IConsumer) + + def __init__(self): + self.contents = "" + + def registerProducer(self, producer, streaming): + assert streaming + assert IPushProducer.providedBy(producer) + + def write(self, data): + self.contents += data + + def unregisterProducer(self): + pass class SystemTest(SystemTestMixin, unittest.TestCase): @@ -159,6 +176,14 @@ class SystemTest(SystemTestMixin, unittest.TestCase): self.failUnlessEqual(newdata, DATA) d.addCallback(_download_to_filehandle_done) + consumer = GrabEverythingConsumer() + ct = download.ConsumerAdapter(consumer) + d.addCallback(lambda res: + self.downloader.download(self.uri, ct)) + def _download_to_consumer_done(ign): + self.failUnlessEqual(consumer.contents, DATA) + d.addCallback(_download_to_consumer_done) + def _download_nonexistent_uri(res): baduri = self.mangle_uri(self.uri) log.msg("about to download non-existent URI", level=log.UNUSUAL,