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

Tres Seaver tseaver at palladion.com
Fri Jun 1 08:48:14 EDT 2007


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

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

-=-
Modified: CMF/branches/1.5/CHANGES.txt
===================================================================
--- CMF/branches/1.5/CHANGES.txt	2007-06-01 10:17:32 UTC (rev 76132)
+++ CMF/branches/1.5/CHANGES.txt	2007-06-01 12:48:14 UTC (rev 76133)
@@ -2,6 +2,9 @@
 
   Bug Fixes
 
+    - Backported test fix from 2.1 branch which suppresses race conditions
+      in date-based topic criteria tests.
+
     - Fixed DST-driven test breakage in CMFCalendar by adding an optional
       'zone' argument to the DublineCore methods which return string
       rednitions of date metadata.

Modified: CMF/branches/1.5/CMFTopic/DateCriteria.py
===================================================================
--- CMF/branches/1.5/CMFTopic/DateCriteria.py	2007-06-01 10:17:32 UTC (rev 76132)
+++ CMF/branches/1.5/CMFTopic/DateCriteria.py	2007-06-01 12:48:14 UTC (rev 76133)
@@ -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.5/CMFTopic/tests/test_DateC.py
===================================================================
--- CMF/branches/1.5/CMFTopic/tests/test_DateC.py	2007-06-01 10:17:32 UTC (rev 76132)
+++ CMF/branches/1.5/CMFTopic/tests/test_DateC.py	2007-06-01 12:48:14 UTC (rev 76133)
@@ -30,7 +30,13 @@
 from Products.CMFTopic.Topic import Topic
 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
@@ -47,6 +53,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
 
@@ -171,6 +184,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
@@ -182,6 +196,9 @@
             dummy_ob.reindexObject()
 
 
+    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.5/CMFTopic/version.txt
===================================================================
--- CMF/branches/1.5/CMFTopic/version.txt	2007-06-01 10:17:32 UTC (rev 76132)
+++ CMF/branches/1.5/CMFTopic/version.txt	2007-06-01 12:48:14 UTC (rev 76133)
@@ -1 +1 @@
-CMF-1.5.7
+CMF-1.5.7+



More information about the CMF-checkins mailing list