changeset 608:16964b4b2f6b

add test for time.time() vs. os.stat().st_mtime consistency
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 30 Apr 2006 16:38:35 +0200
parents e501a537ca6a
children a188f23ba223 4840926790f5
files MoinMoin/_tests/test_util_lock.py
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_util_lock.py	Wed Apr 26 22:31:35 2006 +0200
+++ b/MoinMoin/_tests/test_util_lock.py	Sun Apr 30 16:38:35 2006 +0200
@@ -17,11 +17,30 @@
     
     def setUp(self):
         self.test_dir = tempfile.mkdtemp('', 'lock_')
+        self.test_dir_mtime_goal = time.time()
+        self.test_dir_mtime_reported = os.stat(self.test_dir).st_mtime
         self.lock_dir = os.path.join(self.test_dir, "lock")
         
     def tearDown(self):
         shutil.rmtree(self.test_dir)
 
+    def testBrokenTimeAPI(self):
+        """ util.lock: os.stat().mtime consistency with time.time()
+        
+            the timestamp os.stat reports as st_mtime on a fresh file should
+            be the same (or at least almost the same) as the time time.time()
+            reported at this time.
+            Differences of n*3600s are usually operating system bugs / limitations,
+            Win32 (as of Win XP SP2 + hotfixes 2006-04-30) is broken if you set
+            TZ to a different value than the rest of the system uses.
+            E.g. if you set "TZ=GMT1EDT" (and the rest of the system is setup
+            on german/berlin timezone), it will report 7200s difference in the
+            summer.
+        """
+        diff = self.test_dir_mtime_reported - self.test_dir_mtime_goal # diff should be 0 or near 0
+        self.failUnless(abs(diff) <= 2,
+                        "Operating System time.time / os.stat inconsistent (diff==%.1fs). Locking will NOT work correctly." % float(diff))
+
     def testTimeout(self):
         """ util.lock: ExclusiveLock: raise ValueError for timeout < 2.0 """
         self.assertRaises(ValueError, ExclusiveLock, self.lock_dir, timeout=1.0)