From: Brian Warner Date: Mon, 17 Sep 2007 08:38:54 +0000 (-0700) Subject: provisioning.py: get full test coverage X-Git-Tag: allmydata-tahoe-0.6.0~84 X-Git-Url: https://git.rkrishnan.org/architecture.txt?a=commitdiff_plain;h=79bd7d422d7eba5365143ff6dfdcdecc8aa3eb26;p=tahoe-lafs%2Ftahoe-lafs.git provisioning.py: get full test coverage --- diff --git a/src/allmydata/provisioning.py b/src/allmydata/provisioning.py index 93164e87..adcfbee6 100644 --- a/src/allmydata/provisioning.py +++ b/src/allmydata/provisioning.py @@ -18,14 +18,11 @@ def factorial(n): result = 1 for i in xrange(1, abs(n)+1): result *= i - if n >= 0: - return result - else: - return -result + assert n >= 0 + return result def binomial(n, k): - if not 0 <= k <= n: - return 0 + assert 0 <= k <= n if k == 0 or k == n: return 1 # calculate n!/k! as one product, avoiding factors that @@ -78,12 +75,12 @@ class ProvisioningTool(rend.Page): def add_input(section, text, entry): if section not in sections: sections[section] = [] - sections[section].append(T.div[text, ": ", entry]) + sections[section].extend([T.div[text, ": ", entry], "\n"]) def add_output(section, entry): if section not in sections: sections[section] = [] - sections[section].append(T.div[entry]) + sections[section].extend([entry, "\n"]) def build_section(section): return T.fieldset[T.legend[section], sections[section]] diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 83d73e8a..82bb61b4 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -6,7 +6,7 @@ from twisted.trial import unittest from twisted.internet import defer from twisted.web import client, error, http from twisted.python import failure, log -from allmydata import webish, interfaces, dirnode, uri +from allmydata import webish, interfaces, dirnode, uri, provisioning from allmydata.encode import NotEnoughPeersError from allmydata.util import fileutil import itertools @@ -406,6 +406,13 @@ class Web(WebMixin, unittest.TestCase): d.addCallback(_check2) return d + def test_provisioning_math(self): + self.failUnlessEqual(provisioning.binomial(10, 0), 1) + self.failUnlessEqual(provisioning.binomial(10, 1), 10) + self.failUnlessEqual(provisioning.binomial(10, 2), 45) + self.failUnlessEqual(provisioning.binomial(10, 9), 10) + self.failUnlessEqual(provisioning.binomial(10, 10), 1) + def test_provisioning(self): d = self.GET("/provisioning/") def _check(res): @@ -429,7 +436,32 @@ class Web(WebMixin, unittest.TestCase): def _check2(res): self.failUnless('Tahoe Provisioning Tool' in res) self.failUnless("Share space consumed: 167.01TB" in res) + + fields = {'filled': True, + "num_users": int(50e6), + "files_per_user": 1000, + "space_per_user": int(5e9), + "sharing_ratio": 1.0, + "encoding_parameters": "25-of-100-50", + "num_servers": 30000, + "ownership_mode": "E", + "drive_failure_model": "U", + "drive_size": 1000, + "download_rate": 1000, + "upload_rate": 100, + "delete_rate": 100, + "lease_timer": 7, + } + return self.POST("/provisioning/", **fields) d.addCallback(_check2) + def _check3(res): + self.failUnless("Share space consumed: huge!" in res) + fields = {'filled': True} + return self.POST("/provisioning/", **fields) + d.addCallback(_check3) + def _check4(res): + self.failUnless("Share space consumed:" in res) + d.addCallback(_check4) return d def test_start_html(self):