mutable/retrieve: don't write() after we've been pauseProducer'ed
authorBrian Warner <warner@lothar.com>
Mon, 17 Oct 2011 00:03:47 +0000 (17:03 -0700)
committerBrian Warner <warner@lothar.com>
Mon, 17 Oct 2011 00:24:00 +0000 (17:24 -0700)
commit633641174a7bf18e49bdef581d31fdfcc603d39e
tree88614dff884c50616d0aa89a0120c03cb63f5836
parentfff237be9a0c4dc5b6c6cdfb596fedc877d748ae
mutable/retrieve: don't write() after we've been pauseProducer'ed

This fixes a test failure found against current Twisted trunk in
test_mutable.Filenode.test_retrieve_producer_mdmf (when it uses
PausingAndStoppingConsumer). There must be some sort of race: I could
make it fail against Twisted-11.0 if I just increased the 0.5s delay in
test_download.PausingAndStoppingConsumer to about 0.6s, and could make
Twisted-trunk pass by reducing it to about 0.3s .

I fixed the test (as opposed to the bug) by replacing the delay with a
simple reliable eventually(), and adding extra asserts to fail the test
if the consumer's write() method is called while the producer is
supposed to be paused

The bug itself was that mutable.retrieve.Retrieve wasn't checking the
"stopped" flag after resuming from a pause, and thus delivered one
segment to a consumer that wasn't expecting it. I split out
stopped-flag-checking to separate function, which is now called
immediately after _check_for_paused(). I also cleaned up some Deferred
usage and whitespace.
src/allmydata/mutable/retrieve.py
src/allmydata/test/test_download.py