[CalendarServer-changes] [10284] CalendarServer/branches/users/glyph/queue-locking-and-timing
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jan 4 16:39:56 PST 2013
Revision: 10284
http://trac.calendarserver.org//changeset/10284
Author: glyph at apple.com
Date: 2013-01-04 16:39:55 -0800 (Fri, 04 Jan 2013)
Log Message:
-----------
Failing test for trying to execute the work too soon.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/queue.py
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/queue.py
===================================================================
--- CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/queue.py 2013-01-05 00:39:54 UTC (rev 10283)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/queue.py 2013-01-05 00:39:55 UTC (rev 10284)
@@ -932,15 +932,15 @@
"""
@passthru(self.workItemType.create(self.txn, **self.kw).addCallback)
def whenCreated(item):
- self._whenProposed.callback(None)
+ self._whenProposed.callback(self)
@self.txn.postCommit
def whenDone():
- self._whenCommitted.callback(None)
+ self._whenCommitted.callback(self)
performer = self._chooser.choosePerformer()
@passthru(performer.performWork(item.table, item.workID)
.addCallback)
def performed(result):
- self._whenExecuted.callback(None)
+ self._whenExecuted.callback(self)
@performed.addErrback
def notPerformed(why):
self._whenExecuted.errback(why)
@@ -966,8 +966,8 @@
completed within the transaction of the L{WorkItem.doWork} that
gets executed.
- @return: a L{Deferred} that fires with C{None} when the work has been
- completed remotely.
+ @return: a L{Deferred} that fires with this L{WorkProposal} when the
+ work has been completed remotely.
"""
return _cloneDeferred(self._whenExecuted)
@@ -977,9 +977,10 @@
Let the caller know when the work has been proposed; i.e. when the work
is first transmitted to the database.
- @return: a L{Deferred} that fires with C{None} when the relevant
- commands have been sent to the database to create the L{WorkItem},
- and fails if those commands do not succeed for some reason.
+ @return: a L{Deferred} that fires with this L{WorkProposal} when the
+ relevant commands have been sent to the database to create the
+ L{WorkItem}, and fails if those commands do not succeed for some
+ reason.
"""
return _cloneDeferred(self._whenProposed)
@@ -990,9 +991,9 @@
transaction where the work was proposed has been committed to the
database.
- @return: a L{Deferred} that fires with C{None} when the relevant
- transaction has been committed, or fails if the transaction is not
- committed for any reason.
+ @return: a L{Deferred} that fires with this L{WorkProposal} when the
+ relevant transaction has been committed, or fails if the
+ transaction is not committed for any reason.
"""
return _cloneDeferred(self._whenCommitted)
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:39:54 UTC (rev 10283)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_queue.py 2013-01-05 00:39:55 UTC (rev 10284)
@@ -35,7 +35,7 @@
from twisted.trial.unittest import TestCase
from twisted.internet.defer import (
- Deferred, inlineCallbacks, gatherResults, passthru, returnValue
+ Deferred, inlineCallbacks, gatherResults, passthru#, returnValue
)
from twisted.application.service import Service, MultiService
@@ -74,6 +74,14 @@
+def astimestamp(v):
+ """
+ Convert the given datetime to a POSIX timestamp.
+ """
+ return (v - datetime.datetime.utcfromtimestamp(0)).total_seconds()
+
+
+
class UtilityTests(TestCase):
"""
Tests for supporting utilities.
@@ -328,8 +336,7 @@
# An arbitrary point in time.
fakeNow = datetime.datetime(2012, 12, 12, 12, 12, 12)
# *why* does datetime still not have .astimestamp()
- sinceEpoch = ((fakeNow - datetime.datetime.utcfromtimestamp(0))
- .total_seconds())
+ sinceEpoch = astimestamp(fakeNow)
clock = Clock()
clock.advance(sinceEpoch)
qpool = PeerConnectionPool(clock, dbpool.connection, 0, schema)
@@ -367,7 +374,53 @@
self.assertEquals([x.aPlusB for x in every], [7])
+ @inlineCallbacks
+ def test_notBeforeWhenEnqueueing(self):
+ """
+ L{PeerConnectionPool}
+ """
+ dbpool = buildConnectionPool(self, schemaText + nodeSchema)
+ fakeNow = datetime.datetime(2012, 12, 12, 12, 12, 12)
+ sinceEpoch = astimestamp(fakeNow)
+ clock = Clock()
+ clock.advance(sinceEpoch)
+ qpool = PeerConnectionPool(clock, dbpool.connection, 0, schema)
+ realChoosePerformer = qpool.choosePerformer
+ performerChosen = []
+ def catchPerformerChoice():
+ result = realChoosePerformer()
+ performerChosen.append(True)
+ return result
+ qpool.choosePerformer = catchPerformerChoice
+ @transactionally(dbpool.connection)
+ def check(txn):
+ return qpool.enqueueWork(
+ txn, DummyWorkItem,
+ notBefore=datetime.datetime(2012, 12, 12, 12, 12, 20)
+ ).whenProposed()
+ proposal = yield check
+
+ # This is going to schedule the work to happen with some asynchronous
+ # I/O in the middle; this is a problem because how do we know when it's
+ # time to check to see if the work has started? We need to intercept
+ # the thing that kicks off the work; we can then wait for the work
+ # itself.
+
+ self.assertEquals(performerChosen, [])
+
+ # Advance to exactly the appointed second.
+ clock.advance(20 - 12)
+ self.assertEquals(performerChosen, [True])
+
+ # FIXME: if this fails, it will hang, but that's better than no
+ # notification that it is broken at all.
+
+ result = yield proposal.whenExecuted()
+ self.assertIdentical(result, proposal)
+
+
+
class HalfConnection(object):
def __init__(self, protocol):
self.protocol = protocol
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130104/ade451ba/attachment-0001.html>
More information about the calendarserver-changes
mailing list