[Checkins] SVN: CMF/branches/1.6/C Backported test fix from 2.1 branch which suppresses race conditions in date-based topic criteria tests.

Tres Seaver tseaver at palladion.com
Mon May 21 09:24:06 EDT 2007


Log message for revision 75860:
  Backported test fix from 2.1 branch which suppresses race conditions in date-based topic criteria tests.
  

Changed:
  U   CMF/branches/1.6/CHANGES.txt
  U   CMF/branches/1.6/CMFTopic/DateCriteria.py
  U   CMF/branches/1.6/CMFTopic/tests/test_DateC.py
  U   CMF/branches/1.6/CMFTopic/version.txt

-=-
Modified: CMF/branches/1.6/CHANGES.txt
===================================================================
--- CMF/branches/1.6/CHANGES.txt	2007-05-21 11:49:38 UTC (rev 75859)
+++ CMF/branches/1.6/CHANGES.txt	2007-05-21 13:24:05 UTC (rev 75860)
@@ -1,3 +1,10 @@
+After CMF 1.6.4
+
+  Bug Fixes
+
+    - Backported test fix from 2.1 branch which suppresses race conditions
+      in date-based topic criteria tests.
+
 CMF 1.6.4 (2007/05/15):
 
   (No changes since 1.6.4-beta)

Modified: CMF/branches/1.6/CMFTopic/DateCriteria.py
===================================================================
--- CMF/branches/1.6/CMFTopic/DateCriteria.py	2007-05-21 11:49:38 UTC (rev 75859)
+++ CMF/branches/1.6/CMFTopic/DateCriteria.py	2007-05-21 13:24:05 UTC (rev 75860)
@@ -25,6 +25,7 @@
 from interfaces import Criterion
 from Topic import Topic
 
+_as_of = DateTime  # Allow for controlled value when testing
 
 class FriendlyDateCriterion( AbstractCriterion ):
     """
@@ -126,7 +127,8 @@
                 elif operation == 'min':
                     operation = 'max'
 
-            date = DateTime() + value
+            now = _as_of()
+            date = now + value
 
             if operation == 'within_day':
                 # When items within a day are requested, the range is between
@@ -137,7 +139,7 @@
             elif operation == 'min':
                 if value != 0:
                     if self.daterange == 'old':
-                        date_range = (date, DateTime())
+                        date_range = (date, now)
                         return ( ( field, { 'query': date_range
                                           , 'range': 'min:max'
                                           } ), )
@@ -154,7 +156,7 @@
                     if self.daterange == 'old':
                         return ((field, {'query': date, 'range': operation}),)
                     else:
-                        date_range = (DateTime(), date.latestTime())
+                        date_range = (now, date.latestTime())
                         return ( ( field, { 'query': date_range
                                           , 'range': 'min:max'
                                           } ), )

Modified: CMF/branches/1.6/CMFTopic/tests/test_DateC.py
===================================================================
--- CMF/branches/1.6/CMFTopic/tests/test_DateC.py	2007-05-21 11:49:38 UTC (rev 75859)
+++ CMF/branches/1.6/CMFTopic/tests/test_DateC.py	2007-05-21 13:24:05 UTC (rev 75860)
@@ -28,7 +28,13 @@
 
 from common import CriterionTestCase
 
+def _replace_DC__as_of(new_callable):
+    from Products.CMFTopic import DateCriteria
+    old_value = DateCriteria._as_of
+    DateCriteria._as_of = new_callable
+    return old_value
 
+
 class FriendlyDateCriterionTests(CriterionTestCase):
 
     lessThanFiveDaysOld = { 'value': 5
@@ -45,6 +51,13 @@
             , 'daterange': 'ahead'
             }
 
+    def setUp(self):
+        self._now = DateTime()
+        self._old_as_of = _replace_DC__as_of(lambda: self._now)
+
+    def tearDown(self):
+        _replace_DC__as_of(self._old_as_of)
+
     def _getTargetClass(self):
         from Products.CMFTopic.DateCriteria import FriendlyDateCriterion
 
@@ -181,6 +194,7 @@
         type_crit.edit(value='Dummy Content')
         self.criterion = self.topic.getCriterion('modified')
         self.now = DateTime()
+        self._old_as_of = _replace_DC__as_of(lambda: self.now)
 
         for i in self.day_diffs:
             dummy_id = 'dummy%i' % i
@@ -196,6 +210,9 @@
         PlacelessSetup.tearDown(self)
 
 
+    def beforeTearDown(self):
+        _replace_DC__as_of(self._old_as_of)
+
     def test_Harness(self):
         # Make sure the test harness is set up OK
         ob_values = self.site.objectValues(['Dummy'])

Modified: CMF/branches/1.6/CMFTopic/version.txt
===================================================================
--- CMF/branches/1.6/CMFTopic/version.txt	2007-05-21 11:49:38 UTC (rev 75859)
+++ CMF/branches/1.6/CMFTopic/version.txt	2007-05-21 13:24:05 UTC (rev 75860)
@@ -1 +1 @@
-CMF-1.6.4
+CMF-1.6.4+



More information about the Checkins mailing list