From d90a3ed7f8a7d721fe59a2141529d81636a23fde Mon Sep 17 00:00:00 2001 From: Brian Warner <warner@allmydata.com> Date: Mon, 6 Oct 2008 15:50:37 -0700 Subject: [PATCH] test_system: add test coverage for immutable download.ConsumerAdapter, remove debug messages --- src/allmydata/immutable/download.py | 4 ++-- src/allmydata/immutable/filenode.py | 2 -- src/allmydata/test/test_system.py | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) 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, -- 2.45.2