<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12468] CalendarServer/branches/users/cdaboo/scheduling-queue-refresh</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12468">12468</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-01-28 17:45:15 -0800 (Tue, 28 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Checkpoint: tests for queued invite/reply (and fix reply).</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserscdabooschedulingqueuerefreshtwistedcaldavicalpy">CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/twistedcaldav/ical.py</a></li>
<li><a href="#CalendarServerbranchesuserscdabooschedulingqueuerefreshtxdavcaldavdatastoreschedulingworkpy">CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/txdav/caldav/datastore/scheduling/work.py</a></li>
<li><a href="#CalendarServerbranchesuserscdabooschedulingqueuerefreshtxdavcommondatastoretestutilpy">CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/txdav/common/datastore/test/util.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserscdabooschedulingqueuerefreshtxdavcaldavdatastoretesttest_queue_schedulingpy">CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/txdav/caldav/datastore/test/test_queue_scheduling.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserscdabooschedulingqueuerefreshtwistedcaldavicalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/twistedcaldav/ical.py (12467 => 12468)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/twistedcaldav/ical.py        2014-01-28 19:56:12 UTC (rev 12467)
+++ CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/twistedcaldav/ical.py        2014-01-29 01:45:15 UTC (rev 12468)
</span><span class="lines">@@ -3652,7 +3652,12 @@
</span><span class="cx"> 
</span><span class="cx">     icalstr = str(icalstr).replace(&quot;\r\n &quot;, &quot;&quot;)
</span><span class="cx">     icalstr = icalstr.replace(&quot;\n &quot;, &quot;&quot;)
</span><del>-    icalstr = &quot;\r\n&quot;.join([line for line in icalstr.splitlines() if not line.startswith(&quot;DTSTAMP&quot;)])
</del><ins>+    lines = [line for line in icalstr.splitlines() if not line.startswith(&quot;DTSTAMP&quot;)]
+    for ctr, line in enumerate(lines[:]):
+        pos = line.find(&quot;;X-CALENDARSERVER-DTSTAMP=&quot;)
+        if pos != -1:
+            lines[ctr] = line[:pos] + line[pos + len(&quot;;X-CALENDARSERVER-DTSTAMP=&quot;) + 16:]
+    icalstr = &quot;\r\n&quot;.join(lines)
</ins><span class="cx">     return icalstr + &quot;\r\n&quot;
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdabooschedulingqueuerefreshtxdavcaldavdatastoreschedulingworkpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/txdav/caldav/datastore/scheduling/work.py (12467 => 12468)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/txdav/caldav/datastore/scheduling/work.py        2014-01-28 19:56:12 UTC (rev 12467)
+++ CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/txdav/caldav/datastore/scheduling/work.py        2014-01-29 01:45:15 UTC (rev 12468)
</span><span class="lines">@@ -22,7 +22,6 @@
</span><span class="cx"> 
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue, Deferred
</span><span class="cx"> 
</span><del>-from twistedcaldav import caldavxml
</del><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.ical import Component
</span><span class="cx"> 
</span><span class="lines">@@ -33,6 +32,7 @@
</span><span class="cx"> 
</span><span class="cx"> import datetime
</span><span class="cx"> import hashlib
</span><ins>+from pycalendar.datetime import DateTime
</ins><span class="cx"> 
</span><span class="cx"> __all__ = [
</span><span class="cx">     &quot;ScheduleOrganizerWork&quot;,
</span><span class="lines">@@ -49,10 +49,44 @@
</span><span class="cx">     Base class for common schedule work item behavior.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+    # Track when all work is complete (needed for unit tests)
+    _allDoneCallback = None
+    _queued = 0
+
</ins><span class="cx">     # Schedule work is grouped based on calendar object UID
</span><span class="cx">     group = property(lambda self: &quot;ScheduleWork:%s&quot; % (self.icalendarUid,))
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @classmethod
+    def allDone(cls):
+        d = Deferred()
+        cls._allDoneCallback = d.callback
+        cls._queued = 0
+        return d
+
+
+    @classmethod
+    def _enqueued(cls):
+        &quot;&quot;&quot;
+        Called when a new item is enqueued - using for tracking purposes.
+        &quot;&quot;&quot;
+        ScheduleWorkMixin._queued += 1
+
+
+    def _dequeued(self):
+        &quot;&quot;&quot;
+        Called when an item is dequeued - using for tracking purposes. We call
+        the callback when the last item is dequeued.
+        &quot;&quot;&quot;
+        ScheduleWorkMixin._queued -= 1
+        if ScheduleWorkMixin._queued == 0:
+            if ScheduleWorkMixin._allDoneCallback:
+                def _post():
+                    ScheduleWorkMixin._allDoneCallback(None)
+                    ScheduleWorkMixin._allDoneCallback = None
+                self.transaction.postCommit(_post)
+
+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def handleSchedulingResponse(self, response, calendar, resource, is_organizer):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -73,10 +107,10 @@
</span><span class="cx"> 
</span><span class="cx">         # Map each recipient in the response to a status code
</span><span class="cx">         changed = False
</span><ins>+        propname = calendar.mainComponent().recipientPropertyName() if is_organizer else &quot;ORGANIZER&quot;
</ins><span class="cx">         for item in response.responses:
</span><del>-            assert isinstance(item, caldavxml.Response), &quot;Wrong element in response&quot;
-            recipient = str(item.children[0].children[0])
-            status = str(item.children[1])
</del><ins>+            recipient = str(item.recipient.children[0])
+            status = str(item.reqstatus)
</ins><span class="cx">             statusCode = status.split(&quot;;&quot;)[0]
</span><span class="cx"> 
</span><span class="cx">             # Now apply to each ATTENDEE/ORGANIZER in the original data only if not 1.2
</span><span class="lines">@@ -84,7 +118,7 @@
</span><span class="cx">                 calendar.setParameterToValueForPropertyWithValue(
</span><span class="cx">                     &quot;SCHEDULE-STATUS&quot;,
</span><span class="cx">                     statusCode,
</span><del>-                    &quot;ATTENDEE&quot; if is_organizer else &quot;ORGANIZER&quot;,
</del><ins>+                    propname,
</ins><span class="cx">                     recipient,
</span><span class="cx">                 )
</span><span class="cx">                 changed = True
</span><span class="lines">@@ -102,8 +136,6 @@
</span><span class="cx">     their calendar object resource.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-    _allDoneCallback = None
-
</del><span class="cx">     @classmethod
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def schedule(cls, txn, uid, action, home, resource, calendar, organizer, smart_merge):
</span><span class="lines">@@ -129,6 +161,7 @@
</span><span class="cx">             icalendarText=calendar.getTextWithTimezones(includeTimezones=not config.EnableTimezonesByReference) if calendar else None,
</span><span class="cx">             smartMerge=smart_merge
</span><span class="cx">         ))
</span><ins>+        cls._enqueued()
</ins><span class="cx">         yield proposal.whenProposed()
</span><span class="cx">         log.debug(&quot;ScheduleOrganizerWork - enqueued for ID: {id}, UID: {uid}, organizer: {org}&quot;, id=proposal.workItem.workID, uid=uid, org=organizer)
</span><span class="cx"> 
</span><span class="lines">@@ -144,13 +177,6 @@
</span><span class="cx">         returnValue(len(rows) &gt; 0)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @classmethod
-    def allDone(cls):
-        d = Deferred()
-        cls._allDoneCallback = d.callback
-        return d
-
-
</del><span class="cx">     @inlineCallbacks
</span><span class="cx">     def doWork(self):
</span><span class="cx"> 
</span><span class="lines">@@ -170,8 +196,7 @@
</span><span class="cx">             scheduler = ImplicitScheduler()
</span><span class="cx">             yield scheduler.queuedOrganizerProcessing(self.transaction, scheduleActionFromSQL[self.scheduleAction], home, resource, self.icalendarUid, calendar, self.smartMerge)
</span><span class="cx"> 
</span><del>-            if self._allDoneCallback:
-                self._allDoneCallback(None)
</del><ins>+            self._dequeued()
</ins><span class="cx"> 
</span><span class="cx">         except Exception, e:
</span><span class="cx">             log.debug(&quot;ScheduleOrganizerWork - exception ID: {id}, UID: '{uid}', {err}&quot;, id=self.workID, uid=self.icalendarUid, err=str(e))
</span><span class="lines">@@ -229,8 +254,11 @@
</span><span class="cx">             icalendarUid=resource.uid(),
</span><span class="cx">             homeResourceID=home.id(),
</span><span class="cx">             resourceID=resource.id(),
</span><del>-            changedRids=&quot;,&quot;.join(changedRids) if changedRids else None,
</del><ins>+
+            # Serialize None as &quot;&quot;
+            changedRids=&quot;,&quot;.join(map(lambda x: &quot;&quot; if x is None else str(x), changedRids)) if changedRids else None,
</ins><span class="cx">         ))
</span><ins>+        cls._enqueued()
</ins><span class="cx">         yield proposal.whenProposed()
</span><span class="cx">         log.debug(&quot;ScheduleReplyWork - enqueued for ID: {id}, UID: {uid}, attendee: {att}&quot;, id=proposal.workItem.workID, uid=resource.uid(), att=attendee)
</span><span class="cx"> 
</span><span class="lines">@@ -257,7 +285,8 @@
</span><span class="cx">             calendar = (yield resource.componentForUser())
</span><span class="cx">             organizer = calendar.validOrganizerForScheduling()
</span><span class="cx"> 
</span><del>-            changedRids = self.changedRids.split(&quot;,&quot;) if self.changedRids else None
</del><ins>+            # Deserialize &quot;&quot; as None
+            changedRids = map(lambda x: DateTime.parseText(x) if x else None, self.changedRids.split(&quot;,&quot;)) if self.changedRids else None
</ins><span class="cx"> 
</span><span class="cx">             log.debug(&quot;ScheduleReplyWork - running for ID: {id}, UID: {uid}, attendee: {att}&quot;, id=self.workID, uid=calendar.resourceUID(), att=attendee)
</span><span class="cx"> 
</span><span class="lines">@@ -270,6 +299,8 @@
</span><span class="cx">             response = (yield self.sendToOrganizer(home, &quot;REPLY&quot;, itipmsg, attendee, organizer))
</span><span class="cx">             yield self.handleSchedulingResponse(response, calendar, resource, False)
</span><span class="cx"> 
</span><ins>+            self._dequeued()
+
</ins><span class="cx">         except Exception, e:
</span><span class="cx">             log.debug(&quot;ScheduleReplyWork - exception ID: {id}, UID: '{uid}', {err}&quot;, id=self.workID, uid=calendar.resourceUID(), err=str(e))
</span><span class="cx">             raise
</span><span class="lines">@@ -306,6 +337,7 @@
</span><span class="cx">             homeResourceID=home.id(),
</span><span class="cx">             icalendarText=calendar.getTextWithTimezones(includeTimezones=not config.EnableTimezonesByReference),
</span><span class="cx">         ))
</span><ins>+        cls._enqueued()
</ins><span class="cx">         yield proposal.whenProposed()
</span><span class="cx">         log.debug(&quot;ScheduleReplyCancelWork - enqueued for ID: {id}, UID: {uid}, attendee: {att}&quot;, id=proposal.workItem.workID, uid=calendar.resourceUID(), att=attendee)
</span><span class="cx"> 
</span><span class="lines">@@ -330,6 +362,8 @@
</span><span class="cx">             # Send scheduling message - no need to process response as original resource is gone
</span><span class="cx">             yield self.sendToOrganizer(home, &quot;CANCEL&quot;, itipmsg, attendee, organizer)
</span><span class="cx"> 
</span><ins>+            self._dequeued()
+
</ins><span class="cx">         except Exception, e:
</span><span class="cx">             log.debug(&quot;ScheduleReplyCancelWork - exception ID: {id}, UID: '{uid}', {err}&quot;, id=self.workID, uid=calendar.resourceUID(), err=str(e))
</span><span class="cx">             raise
</span><span class="lines">@@ -409,6 +443,7 @@
</span><span class="cx">             resourceID=organizer_resource.id(),
</span><span class="cx">             notBefore=notBefore
</span><span class="cx">         ))
</span><ins>+        cls._enqueued()
</ins><span class="cx">         yield proposal.whenProposed()
</span><span class="cx">         log.debug(&quot;ScheduleRefreshWork - enqueued for ID: {id}, UID: {uid}, attendees: {att}&quot;, id=proposal.workItem.workID, uid=organizer_resource.uid(), att=&quot;,&quot;.join(attendeesToRefresh))
</span><span class="cx"> 
</span><span class="lines">@@ -464,9 +499,13 @@
</span><span class="cx">                 notBefore=notBefore
</span><span class="cx">             )
</span><span class="cx"> 
</span><ins>+            self._enqueued()
+
</ins><span class="cx">         # Do refresh
</span><span class="cx">         yield self._doDelayedRefresh(attendeesToProcess)
</span><span class="cx"> 
</span><ins>+        self._dequeued()
+
</ins><span class="cx">         log.debug(&quot;ScheduleRefreshWork - done for ID: {id}, UID: {uid}&quot;, id=self.workID, uid=self.icalendarUid)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -542,6 +581,7 @@
</span><span class="cx">             partstat=partstat,
</span><span class="cx">             notBefore=notBefore,
</span><span class="cx">         ))
</span><ins>+        cls._enqueued()
</ins><span class="cx">         yield proposal.whenProposed()
</span><span class="cx">         log.debug(&quot;ScheduleAutoReplyWork - enqueued for ID: {id}, UID: {uid}&quot;, id=proposal.workItem.workID, uid=resource.uid())
</span><span class="cx"> 
</span><span class="lines">@@ -559,6 +599,8 @@
</span><span class="cx">         # Do reply
</span><span class="cx">         yield self._sendAttendeeAutoReply()
</span><span class="cx"> 
</span><ins>+        self._dequeued()
+
</ins><span class="cx">         log.debug(&quot;ScheduleAutoReplyWork - done for ID: {id}, UID: {uid}&quot;, id=self.workID, uid=self.icalendarUid)
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdabooschedulingqueuerefreshtxdavcaldavdatastoretesttest_queue_schedulingpy"></a>
<div class="addfile"><h4>Added: CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/txdav/caldav/datastore/test/test_queue_scheduling.py (0 => 12468)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/txdav/caldav/datastore/test/test_queue_scheduling.py                                (rev 0)
+++ CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/txdav/caldav/datastore/test/test_queue_scheduling.py        2014-01-29 01:45:15 UTC (rev 12468)
</span><span class="lines">@@ -0,0 +1,254 @@
</span><ins>+##
+# Copyright (c) 2014 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from twisted.internet.defer import inlineCallbacks, returnValue
+
+from twext.python.clsprop import classproperty
+from twistedcaldav.config import config
+from txdav.caldav.datastore.scheduling.work import ScheduleWorkMixin
+from txdav.caldav.datastore.test.util import CommonStoreTests
+from txdav.common.datastore.test.util import componentUpdate
+from twistedcaldav.ical import normalize_iCalStr
+
+class BaseQueueSchedulingTests(CommonStoreTests):
+
+    &quot;&quot;&quot;
+    Test store-based calendar sharing.
+    &quot;&quot;&quot;
+
+    @inlineCallbacks
+    def setUp(self):
+        yield super(BaseQueueSchedulingTests, self).setUp()
+
+        # Enable the queue and make it fast
+        self.patch(config.Scheduling.Options.WorkQueues, &quot;Enabled&quot;, True)
+        self.patch(config.Scheduling.Options.WorkQueues, &quot;RequestDelaySeconds&quot;, 1)
+        self.patch(config.Scheduling.Options.WorkQueues, &quot;ReplyDelaySeconds&quot;, 1)
+        self.patch(config.Scheduling.Options.WorkQueues, &quot;AutoReplyDelaySeconds&quot;, 1)
+        self.patch(config.Scheduling.Options.WorkQueues, &quot;AttendeeRefreshBatchDelaySeconds&quot;, 1)
+        self.patch(config.Scheduling.Options.WorkQueues, &quot;AttendeeRefreshBatchIntervalSeconds&quot;, 1)
+
+
+    @classproperty(cache=False)
+    def requirements(cls): #@NoSelf
+        return {
+        &quot;user01&quot;: {
+            &quot;calendar&quot;: {
+            },
+            &quot;inbox&quot;: {
+            },
+        },
+        &quot;user02&quot;: {
+            &quot;calendar&quot;: {
+            },
+            &quot;inbox&quot;: {
+            },
+        },
+        &quot;user03&quot;: {
+            &quot;calendar&quot;: {
+            },
+            &quot;inbox&quot;: {
+            },
+        },
+    }
+
+
+    @inlineCallbacks
+    def _getOneResource(self, home, calendar_name):
+        &quot;&quot;&quot;
+        Get the one resources expected in a collection
+        &quot;&quot;&quot;
+        inbox = yield self.calendarUnderTest(home=home, name=calendar_name)
+        objs = yield inbox.objectResources()
+        self.assertEqual(len(objs), 1)
+        returnValue(objs[0])
+
+
+    @inlineCallbacks
+    def _testOneResource(self, home, calendar_name, data):
+        &quot;&quot;&quot;
+        Get the one resources expected in a collection
+        &quot;&quot;&quot;
+        inbox = yield self.calendarUnderTest(home=home, name=calendar_name)
+        objs = yield inbox.objectResources()
+        self.assertEqual(len(objs), 1)
+
+        caldata = yield objs[0].componentForUser()
+        self.assertEqual(normalize_iCalStr(caldata), normalize_iCalStr(componentUpdate(data)))
+
+
+
+class SimpleSchedulingTests(BaseQueueSchedulingTests):
+
+    @inlineCallbacks
+    def test_invite_reply(self):
+        &quot;&quot;&quot;
+        Test simple invite/reply roundtrip.
+        &quot;&quot;&quot;
+
+        data1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:{now}T000000Z
+DURATION:PT1H
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+DTSTAMP:20051222T210507Z
+ORGANIZER:mailto:user01@example.com
+SUMMARY:1
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        data2 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:{now}T000000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:uuid:user01
+SUMMARY:1
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        data3 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+METHOD:REQUEST
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:{now}T000000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;RSVP=TRUE:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:uuid:user01
+SUMMARY:1
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        data4 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:{now}T000000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;RSVP=TRUE:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:uuid:user01
+SUMMARY:1
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        data5 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:{now}T000000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=ACCEPTED:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:uuid:user01
+SUMMARY:1
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        data6 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:{now}T000000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=ACCEPTED;SCHEDULE-STATUS=2.0:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:uuid:user01
+SUMMARY:1
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        data7 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+METHOD:REPLY
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:{now}T000000Z
+DURATION:PT1H
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=ACCEPTED:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01@example.com:urn:uuid:user01
+SUMMARY:1
+REQUEST-STATUS:2.0;Success
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        data8 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:{now}T000000Z
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;PARTSTAT=ACCEPTED:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01@example.com;SCHEDULE-STATUS=1.2:urn:uuid:user01
+SUMMARY:1
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+        waitForWork = ScheduleWorkMixin.allDone()
+        calendar = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield calendar.createCalendarObjectWithName(&quot;data1.ics&quot;, componentUpdate(data1))
+        yield self.commit()
+
+        yield waitForWork
+
+        yield self._testOneResource(&quot;user01&quot;, &quot;calendar&quot;, data2)
+        yield self._testOneResource(&quot;user02&quot;, &quot;inbox&quot;, data3)
+        yield self._testOneResource(&quot;user02&quot;, &quot;calendar&quot;, data4)
+        yield self.commit()
+
+        waitForWork = ScheduleWorkMixin.allDone()
+        cobj = yield self._getOneResource(&quot;user02&quot;, &quot;calendar&quot;)
+        yield cobj.setComponent(componentUpdate(data5))
+        yield self.commit()
+
+        yield waitForWork
+
+        yield self._testOneResource(&quot;user01&quot;, &quot;calendar&quot;, data6)
+        yield self._testOneResource(&quot;user01&quot;, &quot;inbox&quot;, data7)
+        yield self._testOneResource(&quot;user02&quot;, &quot;calendar&quot;, data8)
</ins></span></pre></div>
<a id="CalendarServerbranchesuserscdabooschedulingqueuerefreshtxdavcommondatastoretestutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/txdav/common/datastore/test/util.py (12467 => 12468)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/txdav/common/datastore/test/util.py        2014-01-28 19:56:12 UTC (rev 12467)
+++ CalendarServer/branches/users/cdaboo/scheduling-queue-refresh/txdav/common/datastore/test/util.py        2014-01-29 01:45:15 UTC (rev 12468)
</span><span class="lines">@@ -529,7 +529,7 @@
</span><span class="cx">     return data % {&quot;now&quot;: nowYear}
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-dateSubstitutions = {}
</del><ins>+relativeDateSubstitutions = {}
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> def componentUpdate(data):
</span><span class="lines">@@ -537,24 +537,24 @@
</span><span class="cx">     Update the supplied iCalendar data so that all dates are updated to the current year.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-    if len(dateSubstitutions) == 0:
</del><ins>+    if len(relativeDateSubstitutions) == 0:
</ins><span class="cx">         now = DateTime.getToday()
</span><span class="cx"> 
</span><del>-        dateSubstitutions[&quot;now&quot;] = now
</del><ins>+        relativeDateSubstitutions[&quot;now&quot;] = now
</ins><span class="cx"> 
</span><span class="cx">         for i in range(30):
</span><span class="cx">             attrname = &quot;now_back%s&quot; % (i + 1,)
</span><del>-            setattr(self, attrname, now.duplicate())
-            getattr(self, attrname).offsetDay(-(i + 1))
-            dateSubstitutions[attrname] = getattr(self, attrname)
</del><ins>+            dt = now.duplicate()
+            dt.offsetDay(-(i + 1))
+            relativeDateSubstitutions[attrname] = dt
</ins><span class="cx"> 
</span><span class="cx">         for i in range(30):
</span><span class="cx">             attrname = &quot;now_fwd%s&quot; % (i + 1,)
</span><del>-            setattr(self, attrname, now.duplicate())
-            getattr(self, attrname).offsetDay(i + 1)
-            dateSubstitutions[attrname] = getattr(self, attrname)
</del><ins>+            dt = now.duplicate()
+            dt.offsetDay(i + 1)
+            relativeDateSubstitutions[attrname] = dt
</ins><span class="cx"> 
</span><del>-    return Component.fromString(data.format(dateSubstitutions))
</del><ins>+    return Component.fromString(data.format(**relativeDateSubstitutions))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>