[CalendarServer-changes] [7624] CalendarServer/branches/users/glyph/quota/txdav
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jun 20 11:45:36 PDT 2011
Revision: 7624
http://trac.macosforge.org/projects/calendarserver/changeset/7624
Author: glyph at apple.com
Date: 2011-06-20 11:45:36 -0700 (Mon, 20 Jun 2011)
Log Message:
-----------
Failing quota-comparison tests, for passing configured value in.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/test/common.py
CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/test/test_file.py
CalendarServer/branches/users/glyph/quota/txdav/common/datastore/test/util.py
Modified: CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/test/common.py 2011-06-20 18:45:24 UTC (rev 7623)
+++ CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/test/common.py 2011-06-20 18:45:36 UTC (rev 7624)
@@ -53,6 +53,7 @@
from twistedcaldav.customxml import InviteNotification, InviteSummary
from txdav.caldav.icalendarstore import IAttachmentStorageTransport
from txdav.caldav.icalendarstore import QuotaExceeded
+from txdav.common.datastore.test.util import deriveQuota
from twistedcaldav.ical import Component
storePath = FilePath(__file__).parent().child("calendar_store")
@@ -1595,6 +1596,18 @@
@inlineCallbacks
+ def test_quotaAllowedBytes(self):
+ """
+ L{ICalendarHome.quotaAllowedBytes} should return the configuration value
+ passed to the calendar store's constructor.
+ """
+ expected = deriveQuota(self.id())
+ home = yield self.homeUnderTest()
+ actual = home.quotaAllowedBytes()
+ self.assertEquals(expected, actual)
+
+
+ @inlineCallbacks
def exceedQuotaTest(self, getit):
"""
If too many bytes are passed to the transport returned by
Modified: CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/test/test_file.py
===================================================================
--- CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/test/test_file.py 2011-06-20 18:45:24 UTC (rev 7623)
+++ CalendarServer/branches/users/glyph/quota/txdav/caldav/datastore/test/test_file.py 2011-06-20 18:45:36 UTC (rev 7624)
@@ -38,6 +38,7 @@
from txdav.caldav.datastore.file import CalendarStore, CalendarHome
from txdav.caldav.datastore.file import Calendar, CalendarObject
+from txdav.common.datastore.test.util import deriveQuota
from txdav.caldav.datastore.test.common import (
CommonTests, event4_text, event1modified_text)
@@ -64,8 +65,10 @@
calendarPath.parent().makedirs()
storePath.copyTo(calendarPath)
- test.calendarStore = CalendarStore(storeRootPath, test.notifierFactory)
- test.txn = test.calendarStore.newTransaction(test.id() + "(old)")
+ testID = test.id()
+ test.calendarStore = CalendarStore(storeRootPath, test.notifierFactory,
+ quota=deriveQuota(testID))
+ test.txn = test.calendarStore.newTransaction(testID + "(old)")
assert test.calendarStore is not None, "No calendar store?"
@@ -77,6 +80,7 @@
assert test.home1 is not None, "No calendar home?"
+
@inlineCallbacks
def setUpCalendar1(test):
yield setUpHome1(test)
Modified: CalendarServer/branches/users/glyph/quota/txdav/common/datastore/test/util.py
===================================================================
--- CalendarServer/branches/users/glyph/quota/txdav/common/datastore/test/util.py 2011-06-20 18:45:24 UTC (rev 7623)
+++ CalendarServer/branches/users/glyph/quota/txdav/common/datastore/test/util.py 2011-06-20 18:45:36 UTC (rev 7624)
@@ -20,6 +20,8 @@
"""
import gc
+from hashlib import md5
+from random import Random
from zope.interface.verify import verifyObject
from zope.interface.exceptions import BrokenMethodImplementation,\
DoesNotImplement
@@ -126,11 +128,12 @@
attachmentRoot.createDirectory()
except OSError:
pass
+ currentTestID = testCase.id()
cp = ConnectionPool(self.sharedService.produceConnection)
+ quota = deriveQuota(currentTestID)
store = CommonDataStore(
- cp.connection, notifierFactory, attachmentRoot
+ cp.connection, notifierFactory, attachmentRoot, quota=quota
)
- currentTestID = testCase.id()
store.label = currentTestID
cp.startService()
def stopIt():
@@ -183,6 +186,31 @@
+def deriveQuota(testID):
+ """
+ Derive a distinctive quota number for a specific test, based on its ID.
+ This generates a quota which is small enough that tests may trivially exceed
+ it if they wish to do so, but distinctive enough that it may be compared
+ without the risk of testing only a single value for quota.
+
+ Since SQL stores are generally built during test construction, it's awkward
+ to have tests which specifically construct a store to inspect quota-related
+ state; this allows us to have the test and the infrastructure agree on a
+ number.
+
+ @param testID: The identifier for a test, as returned by L{TestCase.id}.
+
+ @type testID: C{str}
+ """
+ h = md5()
+ seed = int(h.hexdigest(), 16)
+ r = Random(seed)
+ baseline = 2000
+ fuzz = r.randint(1, 1000)
+ return baseline + fuzz
+
+
+
@inlineCallbacks
def populateCalendarsFrom(requirements, store):
"""
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110620/8045290d/attachment-0001.html>
More information about the calendarserver-changes
mailing list