[CalendarServer-changes] [11064] CalendarServer/branches/users/glyph/start-service-start-loop/twext/ enterprise/test/test_queue.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 18 16:33:01 PDT 2013


Revision: 11064
          http://trac.calendarserver.org//changeset/11064
Author:   glyph at apple.com
Date:     2013-04-18 16:33:01 -0700 (Thu, 18 Apr 2013)
Log Message:
-----------
Test to make sure that startService actually starts the work loop.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/start-service-start-loop/twext/enterprise/test/test_queue.py

Modified: CalendarServer/branches/users/glyph/start-service-start-loop/twext/enterprise/test/test_queue.py
===================================================================
--- CalendarServer/branches/users/glyph/start-service-start-loop/twext/enterprise/test/test_queue.py	2013-04-18 23:33:00 UTC (rev 11063)
+++ CalendarServer/branches/users/glyph/start-service-start-loop/twext/enterprise/test/test_queue.py	2013-04-18 23:33:01 UTC (rev 11064)
@@ -52,7 +52,8 @@
 from twext.enterprise.queue import ConnectionFromPeerNode
 from twext.enterprise.fixtures import buildConnectionPool
 from zope.interface.verify import verifyObject
-from twisted.test.proto_helpers import StringTransport
+from twisted.test.proto_helpers import StringTransport, MemoryReactor
+from twext.enterprise.fixtures import SteppablePoolHelper
 
 from twext.enterprise.queue import _BaseQueuer, NonPerformingQueuer
 import twext.enterprise.queue
@@ -70,6 +71,16 @@
 
 
 
+class MemoryReactorWithClock(MemoryReactor, Clock):
+    """
+    Simulate a real reactor.
+    """
+    def __init__(self):
+        MemoryReactor.__init__(self)
+        Clock.__init__(self)
+
+
+
 def transactionally(transactionCreator):
     """
     Perform the decorated function immediately in a transaction, replacing its
@@ -213,7 +224,6 @@
 
 
 
-
 class WorkItemTests(TestCase):
     """
     A L{WorkItem} is an item of work that can be executed.
@@ -493,6 +503,38 @@
         self.assertEquals(worker2.currentLoad, 1)
 
 
+    def test_poolStartServiceChecksForWork(self):
+        """
+        L{PeerConnectionPool.startService} kicks off the idle work-check loop.
+        """
+        reactor = MemoryReactorWithClock()
+        cph = SteppablePoolHelper(nodeSchema + schemaText)
+        then = datetime.datetime(2012, 12, 12, 12, 12, 0)
+        reactor.advance(astimestamp(then))
+        cph.setUp(self)
+        pcp = PeerConnectionPool(reactor, cph.pool.connection, 4321, schema)
+        now = then + datetime.timedelta(seconds=pcp.queueProcessTimeout * 2)
+        @transactionally(cph.pool.connection)
+        def createOldWork(txn):
+            one = DummyWorkItem.create(txn, workID=1, a=3, b=4, notBefore=then)
+            two = DummyWorkItem.create(txn, workID=2, a=7, b=9, notBefore=now)
+            return gatherResults([one, two])
+        pcp.startService()
+        cph.flushHolders()
+        reactor.advance(pcp.queueProcessTimeout * 2)
+        self.assertEquals(
+            cph.rows("select * from DUMMY_WORK_DONE"),
+            [(1, 7)]
+        )
+        cph.rows("delete from DUMMY_WORK_DONE")
+        reactor.advance(pcp.queueProcessTimeout * 2)
+        self.assertEquals(
+            cph.rows("select * from DUMMY_WORK_DONE"),
+            [(2, 16)]
+        )
+
+
+
 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/20130418/55e2299e/attachment.html>


More information about the calendarserver-changes mailing list