[CalendarServer-changes] [10286] CalendarServer/branches/users/glyph/queue-locking-and-timing
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jan 4 16:39:58 PST 2013
Revision: 10286
http://trac.calendarserver.org//changeset/10286
Author: glyph at apple.com
Date: 2013-01-04 16:39:58 -0800 (Fri, 04 Jan 2013)
Log Message:
-----------
Test and fix for timestamps in the past.
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:57 UTC (rev 10285)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/queue.py 2013-01-05 00:39:58 UTC (rev 10286)
@@ -955,7 +955,7 @@
def notPerformed(why):
self._whenExecuted.errback(why)
reactor = self._chooser.reactor
- when = astimestamp(item.notBefore) - reactor.seconds()
+ when = max(0, astimestamp(item.notBefore) - reactor.seconds())
# TODO: Track the returned DelayedCall so it can be stopped when
# the service stops.
self._chooser.reactor.callLater(when, maybeLater)
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:57 UTC (rev 10285)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_queue.py 2013-01-05 00:39:58 UTC (rev 10286)
@@ -23,7 +23,7 @@
# TODO: There should be a store-building utility within twext.enterprise.
from twisted.protocols.amp import Command
-from twisted.internet.task import Clock
+from twisted.internet.task import Clock as _Clock
from txdav.common.datastore.test.util import buildStore
@@ -54,6 +54,19 @@
from zope.interface.verify import verifyObject
from twisted.test.proto_helpers import StringTransport
+class Clock(_Clock):
+ """
+ More careful L{IReactorTime} fake which mimics the exception behavior of
+ the real reactor.
+ """
+
+ def callLater(self, _seconds, _f, *args, **kw):
+ if _seconds < 0:
+ raise ValueError("%s<0: "%(_seconds,))
+ return super(Clock, self).callLater(_seconds, _f, *args, **kw)
+
+
+
def transactionally(transactionCreator):
"""
Perform the decorated function immediately in a transaction, replacing its
@@ -371,7 +384,9 @@
@inlineCallbacks
def test_notBeforeWhenEnqueueing(self):
"""
- L{PeerConnectionPool}
+ L{PeerConnectionPool.enqueueWork} enqueues some work immediately, but
+ only executes it when enough time has elapsed to allow the C{notBefore}
+ attribute of the given work item to have passed.
"""
dbpool = buildConnectionPool(self, schemaText + nodeSchema)
fakeNow = datetime.datetime(2012, 12, 12, 12, 12, 12)
@@ -414,7 +429,42 @@
self.assertIdentical(result, proposal)
+ @inlineCallbacks
+ def test_notBeforeBefore(self):
+ """
+ L{PeerConnectionPool.enqueueWork} will execute its work immediately if
+ the C{notBefore} attribute of the work item in question is in the past.
+ """
+ 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, a=3, b=9,
+ notBefore=datetime.datetime(2012, 12, 12, 12, 12, 0)
+ ).whenProposed()
+ proposal = yield check
+ clock.advance(1000)
+ # Advance far beyond the given timestamp.
+ self.assertEquals(performerChosen, [True])
+
+ 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/e9a134bf/attachment-0001.html>
More information about the calendarserver-changes
mailing list