[CalendarServer-changes] [10844] CalendarServer/branches/users/sagen/testing/calendarserver/push
source_changes at macosforge.org
source_changes at macosforge.org
Tue Mar 5 09:50:09 PST 2013
Revision: 10844
http://trac.calendarserver.org//changeset/10844
Author: sagen at apple.com
Date: 2013-03-05 09:50:09 -0800 (Tue, 05 Mar 2013)
Log Message:
-----------
Working on push coalescing
Modified Paths:
--------------
CalendarServer/branches/users/sagen/testing/calendarserver/push/notifier.py
CalendarServer/branches/users/sagen/testing/calendarserver/push/test/test_notifier.py
Modified: CalendarServer/branches/users/sagen/testing/calendarserver/push/notifier.py
===================================================================
--- CalendarServer/branches/users/sagen/testing/calendarserver/push/notifier.py 2013-03-05 03:36:01 UTC (rev 10843)
+++ CalendarServer/branches/users/sagen/testing/calendarserver/push/notifier.py 2013-03-05 17:50:09 UTC (rev 10844)
@@ -31,11 +31,12 @@
class PushNotificationWork(WorkItem, fromTable(schema.PUSH_NOTIFICATION_WORK)):
+ group = "PUSH_ID"
+
@inlineCallbacks
def doWork(self):
# FIXME: Coalescing goes here?
-
pushDistributor = self.transaction._pushDistributor
if pushDistributor is not None:
yield pushDistributor.enqueue(self.pushID)
Modified: CalendarServer/branches/users/sagen/testing/calendarserver/push/test/test_notifier.py
===================================================================
--- CalendarServer/branches/users/sagen/testing/calendarserver/push/test/test_notifier.py 2013-03-05 03:36:01 UTC (rev 10843)
+++ CalendarServer/branches/users/sagen/testing/calendarserver/push/test/test_notifier.py 2013-03-05 17:50:09 UTC (rev 10844)
@@ -15,10 +15,14 @@
##
from twistedcaldav.test.util import TestCase
-from calendarserver.push.notifier import PushDistributor, getPubSubAPSConfiguration
+from calendarserver.push.notifier import PushDistributor
+from calendarserver.push.notifier import getPubSubAPSConfiguration
+from calendarserver.push.notifier import PushNotificationWork
from twisted.internet.defer import inlineCallbacks, succeed
from twistedcaldav.config import ConfigDict
+from txdav.common.datastore.test.util import buildStore
+
class StubService(object):
def __init__(self):
self.reset()
@@ -69,3 +73,50 @@
"APSEnvironment": "prod"
}
)
+
+
+class StubDistributor(object):
+ def __init__(self):
+ self.reset()
+
+ def reset(self):
+ self.history = []
+
+ def enqueue(self, pushID):
+ self.history.append(pushID)
+
+class PushNotificationWorkTests(TestCase):
+
+ @inlineCallbacks
+ def test_work(self):
+ self.store = yield buildStore(self, None)
+
+ pushDistributor = StubDistributor()
+
+ def decorateTransaction(txn):
+ txn._pushDistributor = pushDistributor
+
+ self.store.callWithNewTransactions(decorateTransaction)
+
+ txn = self.store.newTransaction()
+ wp = (yield txn.enqueue(PushNotificationWork,
+ pushID="/CalDAV/localhost/foo/",
+ ))
+ yield txn.commit()
+ yield wp.whenExecuted()
+ self.assertEquals(pushDistributor.history, ["/CalDAV/localhost/foo/"])
+
+ pushDistributor.reset()
+ txn = self.store.newTransaction()
+ wp = (yield txn.enqueue(PushNotificationWork,
+ pushID="/CalDAV/localhost/bar/",
+ ))
+ wp = (yield txn.enqueue(PushNotificationWork,
+ pushID="/CalDAV/localhost/bar/",
+ ))
+ wp = (yield txn.enqueue(PushNotificationWork,
+ pushID="/CalDAV/localhost/bar/",
+ ))
+ yield txn.commit()
+ yield wp.whenExecuted()
+ self.assertEquals(pushDistributor.history, ["/CalDAV/localhost/bar/"])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130305/0f180bed/attachment.html>
More information about the calendarserver-changes
mailing list