[CalendarServer-changes] [7596] CalendarServer/trunk/contrib/performance

source_changes at macosforge.org source_changes at macosforge.org
Tue Jun 14 14:25:47 PDT 2011


Revision: 7596
          http://trac.macosforge.org/projects/calendarserver/changeset/7596
Author:   exarkun at twistedmatrix.com
Date:     2011-06-14 14:25:46 -0700 (Tue, 14 Jun 2011)
Log Message:
-----------
Fix a timezone problem with the WorkDistribution used for event creation

Modified Paths:
--------------
    CalendarServer/trunk/contrib/performance/loadtest/config.plist
    CalendarServer/trunk/contrib/performance/stats.py
    CalendarServer/trunk/contrib/performance/test_stats.py

Modified: CalendarServer/trunk/contrib/performance/loadtest/config.plist
===================================================================
--- CalendarServer/trunk/contrib/performance/loadtest/config.plist	2011-06-14 20:53:29 UTC (rev 7595)
+++ CalendarServer/trunk/contrib/performance/loadtest/config.plist	2011-06-14 21:25:46 UTC (rev 7596)
@@ -150,9 +150,15 @@
 		  <key>beginHour</key>
 		  <integer>8</integer>
 
-		  <!-- And the latest hour of a day. -->
+		  <!-- And the latest hour of a day (at which an event will be
+                       scheduled to begin!). -->
 		  <key>endHour</key>
-		  <integer>17</integer>
+		  <integer>16</integer>
+
+                  <!-- The timezone in which the event is scheduled.
+                       (XXX Does this really work right?) -->
+                  <key>tzname</key>
+                  <string>America/Los_Angeles</string>
 		</dict>
 	      </dict>
 	    </dict>

Modified: CalendarServer/trunk/contrib/performance/stats.py
===================================================================
--- CalendarServer/trunk/contrib/performance/stats.py	2011-06-14 20:53:29 UTC (rev 7595)
+++ CalendarServer/trunk/contrib/performance/stats.py	2011-06-14 21:25:46 UTC (rev 7596)
@@ -16,6 +16,8 @@
 
 import random, time, datetime
 
+import pytz
+
 from zope.interface import Interface, implements
 
 from twisted.python.util import FancyEqMixin
@@ -311,16 +313,18 @@
 
     now = staticmethod(datetime.datetime.now)
 
-    def __init__(self, daysOfWeek=["mon", "tue", "wed", "thu", "fri"], beginHour=8, endHour=17):
+    def __init__(self, daysOfWeek=["mon", "tue", "wed", "thu", "fri"], beginHour=8, endHour=17, tzname="UTC"):
         self._daysOfWeek = [self._weekdayNames.index(day) for day in daysOfWeek]
         self._beginHour = beginHour
         self._endHour = endHour
+        self._tzinfo = pytz.timezone(tzname)
         self._helperDistribution = NormalDistribution(
             # Mean 6 workdays in the future
             60 * 60 * 8 * 6,
             # Standard deviation of 4 workdays
             60 * 60 * 8 * 4)
-    
+
+
     def astimestamp(self, dt):
         return time.mktime(dt.timetuple())
 
@@ -347,7 +351,7 @@
 
     def sample(self):
         offset = datetime.timedelta(seconds=self._helperDistribution.sample())
-        beginning = self.now()
+        beginning = self.now(self._tzinfo)
         while offset:
             start, end = self._findWorkAfter(beginning)
             if end - start > offset:

Modified: CalendarServer/trunk/contrib/performance/test_stats.py
===================================================================
--- CalendarServer/trunk/contrib/performance/test_stats.py	2011-06-14 20:53:29 UTC (rev 7595)
+++ CalendarServer/trunk/contrib/performance/test_stats.py	2011-06-14 21:25:46 UTC (rev 7596)
@@ -14,6 +14,7 @@
 # limitations under the License.
 ##
 
+import pytz
 from datetime import datetime
 
 from twisted.trial.unittest import TestCase
@@ -66,16 +67,20 @@
 
 
     def test_workdistribution(self):
-        dist = WorkDistribution(["mon", "wed", "thu", "sat"], 10, 20)
+        tzname = "US/Eastern"
+        tzinfo = pytz.timezone(tzname)
+        print tzinfo
+        dist = WorkDistribution(["mon", "wed", "thu", "sat"], 10, 20, tzname)
         dist._helperDistribution = UniformDiscreteDistribution([35 * 60 * 60 + 30 * 60])
-        dist.now = lambda: datetime(2011, 5, 29, 18, 5, 36)
+        dist.now = lambda tz=None: datetime(2011, 5, 29, 18, 5, 36, tzinfo=tz)
         value = dist.sample()
         self.assertEqual(
             # Move past three workdays - monday, wednesday, thursday - using 30
             # of the hours, and then five and a half hours into the fourth
             # workday, saturday.  Workday starts at 10am, so the sample value
             # is 3:30pm, ie 1530 hours.
-            datetime(2011, 6, 4, 15, 30, 0), datetime.fromtimestamp(value)) 
+            datetime(2011, 6, 4, 15, 30, 0, tzinfo=tzinfo),
+            datetime.fromtimestamp(value, tzinfo))
 
 
     def test_uniform(self):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110614/21b9fe40/attachment.html>


More information about the calendarserver-changes mailing list