[CalendarServer-changes] [10219] CalendarServer/branches/users/glyph/queue-locking-and-timing
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jan 4 16:38:29 PST 2013
Revision: 10219
http://trac.calendarserver.org//changeset/10219
Author: glyph at apple.com
Date: 2013-01-04 16:38:29 -0800 (Fri, 04 Jan 2013)
Log Message:
-----------
Whole-system happy-path test, which, oddly, fails
Modified Paths:
--------------
CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_queue.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/queue-locking-and-timing/
Modified: CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_queue.py
===================================================================
--- CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_queue.py 2013-01-05 00:38:28 UTC (rev 10218)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_queue.py 2013-01-05 00:38:29 UTC (rev 10219)
@@ -18,6 +18,11 @@
Tests for L{twext.enterprise.queue}.
"""
+import datetime
+
+# TODO: There should be a store-building utility within twext.enterprise.
+from txdav.common.datastore.test.util import buildStore
+
from twext.enterprise.dal.syntax import SchemaSyntax
from twext.enterprise.dal.record import fromTable
from twext.enterprise.dal.test.test_parseschema import SchemaTestHelper
@@ -25,13 +30,13 @@
from twext.enterprise.queue import inTransaction, PeerConnectionPool, WorkItem
from twisted.trial.unittest import TestCase
-from twisted.internet.defer import Deferred, inlineCallbacks, gatherResults
+from twisted.internet.defer import Deferred, inlineCallbacks, gatherResults, passthru
from twisted.application.service import Service, MultiService
+from twext.enterprise.dal.syntax import Insert
-from txdav.common.datastore.test.util import buildStore
-
+from twext.enterprise.dal.syntax import Select
class UtilityTests(TestCase):
"""
Tests for supporting utilities.
@@ -81,17 +86,38 @@
def id(self):
return 'worker'
-schemaText = """
- create table DUMMY_WORK_ITEM (WORK_ID integer, CREATED timestamp);
-"""
+SQL = passthru
+
+schemaText = SQL("""
+ create table DUMMY_WORK_ITEM (WORK_ID integer, NOT_BEFORE timestamp,
+ A integer, B integer);
+ create table DUMMY_WORK_DONE (WORK_ID integer, A_PLUS_B integer);
+""")
+
schema = SchemaSyntax(SimpleSchemaHelper().schemaFromString(schemaText))
+dropSQL = ["drop table {name}".format(name=table.model.name)
+ for table in schema]
+
+
class DummyWorkItem(WorkItem, fromTable(schema.DUMMY_WORK_ITEM)):
- pass
+ """
+ Sample L{WorkItem} subclass that adds two integers together and stores them
+ in another table.
+ """
+ group = None
+ def doWork(self):
+ # Perform the work.
+ result = self.a + self.b
+ # Store the result.
+ return (Insert({schema.DUMMY_WORK_DONE.WORK_ID: self.workID,
+ schema.DUMMY_WORK_DONE.A_PLUS_B: result})
+ .on(self.transaction))
+
class PeerConnectionPoolIntegrationTests(TestCase):
"""
L{PeerConnectionPool} is the service responsible for coordinating
@@ -109,8 +135,10 @@
yield inTransaction(lambda: self.store.newTransaction("bonus schema"),
doit)
def deschema():
+ @inlineCallbacks
def deletestuff(txn):
- return txn.execSQL("drop table DUMMY_WORK_ITEM")
+ for stmt in dropSQL:
+ yield txn.execSQL(stmt)
return inTransaction(self.store.newTransaction, deletestuff)
self.addCleanup(deschema)
@@ -150,4 +178,28 @@
return inTransaction(self.store.newTransaction, check)
+ @inlineCallbacks
+ def test_enqueueHappyPath(self):
+ """
+ When a L{WorkItem} is scheduled for execution via
+ L{PeerConnectionPool.enqueueWork} its C{doWork} method will be invoked
+ by the time the L{Deferred} returned from the resulting
+ L{WorkProposal}'s C{whenExecuted} method has fired.
+ """
+ def operation(txn):
+ # TODO: how does 'enqueue' get associated with the transaction? This
+ # is not the fact with a raw t.w.enterprise transaction. Should
+ # probably do something with components.
+ return txn.enqueue(DummyWorkItem, a=3, b=4, workID=4321,
+ notBefore=datetime.datetime.now())
+ result = yield inTransaction(self.store.newTransaction, operation)
+ # Wait for it to be executed. Hopefully this does not time out :-\.
+ yield result.whenExecuted()
+ def op2(txn):
+ return Select([schema.DUMMY_WORK_DONE.WORK_ID,
+ schema.DUMMY_WORK_DONE.A_PLUS_B],
+ From=schema.DUMMY_WORK_DONE).on(txn)
+ rows = yield inTransaction(self.store.newTransaction, op2)
+ self.assertEquals(rows, [(3421, 7)])
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130104/0ca8194f/attachment.html>
More information about the calendarserver-changes
mailing list