fuse/runtests: added 'random scatter' write test
authorrobk-tahoe <robk-tahoe@allmydata.com>
Fri, 3 Oct 2008 23:34:36 +0000 (16:34 -0700)
committerrobk-tahoe <robk-tahoe@allmydata.com>
Fri, 3 Oct 2008 23:34:36 +0000 (16:34 -0700)
this writes the test file in a randomised order, with randomly sized writes.
also for each 'slice' of the file written, a randomly chosen overlapping
write is also made to the file.  this ensures that the file will be written
in its entirety in a thoroughly random order, with many overlapping writes.

contrib/fuse/runtests.py

index cf0097057295dee7cb84a0dddf4124274cdb016f..aa125cfd10ee5ec25b3e55e37d657eb15725ae98 100644 (file)
@@ -492,6 +492,46 @@ class SystemTest (object):
         self._check_write(testcap, name, body)
 
 
+    def test_write_random_scatter(self, testcap, testdir):
+        sz = 2**20
+        name = 'random_scatter'
+        body = os.urandom(sz)
+
+        def rsize(sz=sz):
+            return min(int(random.paretovariate(.25)), sz/12)
+
+        # first chop up whole file into random sized chunks
+        slices = []
+        posn = 0
+        while posn < sz:
+            size = rsize()
+            slices.append( (posn, body[posn:posn+size]) )
+            posn += size
+        random.shuffle(slices) # and randomise their order
+
+        try:
+            path = os.path.join(testdir, name)
+            f = file(path, 'w')
+        except Exception, err:
+            tmpl = 'Could not open file for write at %r: %r'
+            raise TestFailure(tmpl, path, err)
+        try:
+            # write all slices: we hence know entire file is ultimately written
+            # write random excerpts: this provides for mixed and varied overlaps
+            for posn,slice in slices:
+                f.seek(posn)
+                f.write(slice)
+                rposn = random.randint(0,sz)
+                f.seek(rposn)
+                f.write(body[rposn:rposn+rsize()])
+            f.close()
+        except Exception, err:
+            tmpl = 'Could not write to file %r: %r'
+            raise TestFailure(tmpl, path, err)
+
+        self._check_write(testcap, name, body)
+
+
     # Utilities:
     def run_tahoe(self, *args):
         realargs = ('tahoe',) + args