From b49986f80115289021ccffe31e9f11f6c34ff64c Mon Sep 17 00:00:00 2001
From: Kevan Carstensen <kevan@isnotajoke.com>
Date: Sat, 13 Aug 2011 11:39:36 -0700
Subject: [PATCH] test/test_mutable: test for incorrect div_ceil equations

---
 src/allmydata/test/test_mutable.py | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/allmydata/test/test_mutable.py b/src/allmydata/test/test_mutable.py
index 1b7fc9fb..365ca977 100644
--- a/src/allmydata/test/test_mutable.py
+++ b/src/allmydata/test/test_mutable.py
@@ -7,7 +7,7 @@ from twisted.internet.interfaces import IConsumer
 from zope.interface import implements
 from allmydata import uri, client
 from allmydata.nodemaker import NodeMaker
-from allmydata.util import base32, consumer, fileutil
+from allmydata.util import base32, consumer, fileutil, mathutil
 from allmydata.util.hashutil import tagged_hash, ssk_writekey_hash, \
      ssk_pubkey_fingerprint_hash
 from allmydata.util.deferredutil import gatherResults
@@ -3222,6 +3222,28 @@ class Version(GridTestMixin, unittest.TestCase, testutil.ShouldFailMixin, \
         d.addCallback(_read_data)
         return d
 
+    def test_partial_read_starting_on_segment_boundary(self):
+        d = self.mdmf_node.get_best_readable_version()
+        c = consumer.MemoryConsumer()
+        offset = mathutil.next_multiple(128 * 1024, 3)
+        d.addCallback(lambda version:
+            version.read(c, offset, 50))
+        expected = self.data[offset:offset+50]
+        d.addCallback(lambda ignored:
+            self.failUnlessEqual(expected, "".join(c.chunks)))
+        return d
+
+    def test_partial_read_ending_on_segment_boundary(self):
+        d = self.mdmf_node.get_best_readable_version()
+        c = consumer.MemoryConsumer()
+        offset = mathutil.next_multiple(128 * 1024, 3)
+        start = offset - 50
+        d.addCallback(lambda version:
+            version.read(c, start, 51))
+        expected = self.data[offset-50:offset+1]
+        d.addCallback(lambda ignored:
+            self.failUnlessEqual(expected, "".join(c.chunks)))
+        return d
 
     def test_read(self):
         d = self.mdmf_node.get_best_readable_version()
-- 
2.45.2