[CalendarServer-changes] [8323] CalendarServer/branches/users/glyph/multiget-delete/txdav
source_changes at macosforge.org
source_changes at macosforge.org
Fri Nov 18 10:13:31 PST 2011
Revision: 8323
http://trac.macosforge.org/projects/calendarserver/changeset/8323
Author: glyph at apple.com
Date: 2011-11-18 10:13:31 -0800 (Fri, 18 Nov 2011)
Log Message:
-----------
allow for concurrent transaction creation in the tests, and add a test for concurrently deleting calendar objects while another transaction is looking at them
Modified Paths:
--------------
CalendarServer/branches/users/glyph/multiget-delete/txdav/caldav/datastore/test/common.py
CalendarServer/branches/users/glyph/multiget-delete/txdav/common/datastore/test/util.py
Modified: CalendarServer/branches/users/glyph/multiget-delete/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/branches/users/glyph/multiget-delete/txdav/caldav/datastore/test/common.py 2011-11-18 18:13:06 UTC (rev 8322)
+++ CalendarServer/branches/users/glyph/multiget-delete/txdav/caldav/datastore/test/common.py 2011-11-18 18:13:31 UTC (rev 8323)
@@ -257,34 +257,33 @@
@inlineCallbacks
- def homeUnderTest(self):
+ def homeUnderTest(self, txn=None):
"""
Get the calendar home detailed by C{requirements['home1']}.
"""
- returnValue(
- (yield self.transactionUnderTest().calendarHomeWithUID("home1"))
- )
+ if txn is None:
+ txn = self.transactionUnderTest()
+ returnValue((yield txn.calendarHomeWithUID("home1")))
@inlineCallbacks
- def calendarUnderTest(self):
+ def calendarUnderTest(self, txn=None):
"""
Get the calendar detailed by C{requirements['home1']['calendar_1']}.
"""
returnValue((yield
- (yield self.homeUnderTest()).calendarWithName("calendar_1"))
+ (yield self.homeUnderTest(txn)).calendarWithName("calendar_1"))
)
@inlineCallbacks
- def calendarObjectUnderTest(self, name="1.ics"):
+ def calendarObjectUnderTest(self, name="1.ics", txn=None):
"""
Get the calendar detailed by
C{requirements['home1']['calendar_1'][name]}.
"""
- returnValue(
- (yield (yield self.calendarUnderTest())
- .calendarObjectWithName(name)))
+ returnValue((yield (yield self.calendarUnderTest(txn))
+ .calendarObjectWithName(name)))
def test_calendarStoreProvides(self):
@@ -731,6 +730,23 @@
@inlineCallbacks
+ def test_calendarObjectRemoveConcurrent(self):
+ """
+ If a transaction, C{A}, is examining an L{ICalendarObject} C{O} while
+ another transaction, C{B}, deletes O, L{O.text()} should raise an
+ exception.
+ """
+ calendarObject = yield self.calendarObjectUnderTest()
+ ctxn = self.concurrentTransaction()
+ calendar1prime = yield self.calendarUnderTest(ctxn)
+ removal = calendar1prime.removeCalendarObjectWithName("1.ics")
+ retrieval = calendarObject.component()
+ def oneOf(deferreds):
+ pass
+ yield oneOf([removal, retrieval])
+
+
+ @inlineCallbacks
def test_ownerCalendarHome(self):
"""
L{ICalendar.ownerCalendarHome} should match the home UID.
Modified: CalendarServer/branches/users/glyph/multiget-delete/txdav/common/datastore/test/util.py
===================================================================
--- CalendarServer/branches/users/glyph/multiget-delete/txdav/common/datastore/test/util.py 2011-11-18 18:13:06 UTC (rev 8322)
+++ CalendarServer/branches/users/glyph/multiget-delete/txdav/common/datastore/test/util.py 2011-11-18 18:13:31 UTC (rev 8323)
@@ -44,6 +44,7 @@
from twext.enterprise.adbapi2 import ConnectionPool
from twisted.internet.defer import returnValue
from twistedcaldav.notify import Notifier, NodeCreationException
+from twext.enterprise.ienterprise import AlreadyFinishedError
from twistedcaldav.vcard import Component as ABComponent
md5key = PropertyName.fromElement(TwistedGETContentMD5)
@@ -400,7 +401,6 @@
lastTransaction = None
savedStore = None
assertProvides = assertProvides
- lastCommitSetUp = False
def transactionUnderTest(self):
"""
@@ -408,17 +408,29 @@
C[lastTransaction}. Also makes sure to use the same store, saving the
value from C{storeUnderTest}.
"""
- if not self.lastCommitSetUp:
- self.lastCommitSetUp = True
- self.addCleanup(self.commitLast)
- if self.lastTransaction is not None:
- return self.lastTransaction
+ if self.lastTransaction is None:
+ self.lastTransaction = self.concurrentTransaction()
+ return self.lastTransaction
+
+
+ def concurrentTransaction(self):
+ """
+ Create a transaction from C{storeUnderTest} and save it for later
+ clean-up.
+ """
if self.savedStore is None:
self.savedStore = self.storeUnderTest()
self.counter += 1
- txn = self.lastTransaction = self.savedStore.newTransaction(
+ txn = self.savedStore.newTransaction(
self.id() + " #" + str(self.counter)
)
+ @inlineCallbacks
+ def maybeCommitThis():
+ try:
+ yield txn.commit()
+ except AlreadyFinishedError:
+ pass
+ self.addCleanup(maybeCommitThis)
return txn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111118/0188907e/attachment-0001.html>
More information about the calendarserver-changes
mailing list