mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-19 03:06:33 +00:00
provisioning.py: get full test coverage
This commit is contained in:
parent
941d1551a0
commit
79bd7d422d
@ -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]]
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user