[CalendarServer-changes] [10693] CalendarServer/trunk/twext/who

source_changes at macosforge.org source_changes at macosforge.org
Mon Feb 11 16:19:29 PST 2013


Revision: 10693
          http://trac.calendarserver.org//changeset/10693
Author:   wsanchez at apple.com
Date:     2013-02-11 16:19:29 -0800 (Mon, 11 Feb 2013)
Log Message:
-----------
Test reloading

Modified Paths:
--------------
    CalendarServer/trunk/twext/who/test/test_xml.py
    CalendarServer/trunk/twext/who/xml.py

Modified: CalendarServer/trunk/twext/who/test/test_xml.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_xml.py	2013-02-11 23:52:11 UTC (rev 10692)
+++ CalendarServer/trunk/twext/who/test/test_xml.py	2013-02-12 00:19:29 UTC (rev 10693)
@@ -18,6 +18,8 @@
 XML directory service tests
 """
 
+from time import sleep
+
 from twisted.python.filepath import FilePath
 from twisted.internet.defer import inlineCallbacks
 
@@ -181,6 +183,26 @@
         self.assertRaises(AssertionError, setRealmName)
 
 
+    def test_reloadInterval(self):
+        service = self._testService()
+        service.loadRecords(stat=False)
+        lastRefresh = service._lastRefresh
+        self.assertTrue(service._lastRefresh)
+        sleep(1)
+        service.loadRecords(stat=False)
+        self.assertEquals(lastRefresh, service._lastRefresh)
+
+
+    def test_reloadStat(self):
+        service = self._testService()
+        service.loadRecords(loadNow=True)
+        lastRefresh = service._lastRefresh
+        self.assertTrue(service._lastRefresh)
+        sleep(1)
+        service.loadRecords(loadNow=True)
+        self.assertEquals(lastRefresh, service._lastRefresh)
+
+
     @inlineCallbacks
     def test_recordWithUID(self):
         service = self._testService()

Modified: CalendarServer/trunk/twext/who/xml.py
===================================================================
--- CalendarServer/trunk/twext/who/xml.py	2013-02-11 23:52:11 UTC (rev 10692)
+++ CalendarServer/trunk/twext/who/xml.py	2013-02-12 00:19:29 UTC (rev 10693)
@@ -188,7 +188,7 @@
         return self._index
 
 
-    def loadRecords(self, loadNow=False):
+    def loadRecords(self, loadNow=False, stat=True):
         """
         Load records from L{self.filePath}.
 
@@ -208,9 +208,13 @@
         #
         # Punt if we've read the file and it's still the same.
         #
-        cacheTag = (self.filePath.getmtime(), self.filePath.getsize())
-        if cacheTag == self._cacheTag:
-            return
+        if stat:
+            self.filePath.restat()
+            cacheTag = (self.filePath.getModificationTime(), self.filePath.getsize())
+            if cacheTag == self._cacheTag:
+                return
+        else:
+            cacheTag = None
 
         #
         # Open and parse the file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130211/3562be46/attachment.html>


More information about the calendarserver-changes mailing list