summary refs log tree commit diff stats
path: root/test/tc_directory.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/tc_directory.py')
-rw-r--r--test/tc_directory.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/test/tc_directory.py b/test/tc_directory.py
index f97f9913..ebbd6b5e 100644
--- a/test/tc_directory.py
+++ b/test/tc_directory.py
@@ -1,6 +1,7 @@
 import unittest
-import sys, os
+import sys, os, time
 sys.path.append('../code')
+os.stat_float_times(True)
 import directory, fsobject, file, debug
 
 TESTDIR = os.path.realpath(os.path.join(os.path.dirname(sys.argv[0]), 'testdir'))
@@ -78,15 +79,33 @@ class Test1(unittest.TestCase):
 		self.assertRaises(fsobject.FrozenException, clone.load_content)
 
 	def test_load_if_outdated(self):
-		if os.path.exists(TESTFILE): os.unlink(TESTFILE)
+		# modify the directory. If the time between the last modification
+		# was within the filesystems resolution of mtime, we should have a re-load.
+
+		def modify_dir():
+			open(TESTFILE, 'w').close()
+			os.unlink(TESTFILE)
+
+		def mtime():
+			return os.stat(TESTDIR).st_mtime
+
 		dir = directory.Directory(TESTDIR)
 		dir.load()
 
-		open(TESTFILE, 'w').close()
+		# If the modification happens to be in the same second as the
+		# last modification, it will result in mtime having the same
+		# integer value. So we wait until the resolution is exceeded
+		# and mtime differs.
+		old_mtime = mtime()
+		for i in range(50):
+			modify_dir()
+			if old_mtime != mtime(): break
+			time.sleep(0.1)
+		else:
+			# fail after 5 seconds of trying
+			self.fail("Cannot perform test: mtime of TESTDIR is not being updated.")
 
 		self.assertTrue(dir.load_if_outdated())
 
-		os.unlink(TESTFILE)
-
 unittest.main()