[CMF-checkins] CVS: CMF/CMFCore/tests - test_FSPythonScript.py:1.3.14.1

Shane Hathaway shane@cvs.zope.org
Thu, 15 Aug 2002 16:59:14 -0400


Update of /cvs-repository/CMF/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv16618/CMFCore/tests

Modified Files:
      Tag: CMF-1_3-branch
	test_FSPythonScript.py 
Log Message:
Merged fix for collector #37.


=== CMF/CMFCore/tests/test_FSPythonScript.py 1.3 => 1.3.14.1 ===
--- CMF/CMFCore/tests/test_FSPythonScript.py:1.3	Fri Feb 15 14:45:33 2002
+++ CMF/CMFCore/tests/test_FSPythonScript.py	Thu Aug 15 16:59:14 2002
@@ -1,18 +1,43 @@
+import Testing
 import Zope
+from OFS.Folder import Folder
 from unittest import TestCase, TestSuite, makeSuite, main
 from Products.CMFCore.FSPythonScript import FSPythonScript
 from test_DirectoryView import skin_path_name
 from os.path import join
+import sys, time
+from thread import start_new_thread
 
 script_path = join(skin_path_name,'test1.py')
 
 class FSPythonScriptTests( TestCase ):
 
-    def test_GetSize( self ):
-        """ Test get_size returns correct value """
+    def testGetSize(self):
+        # Test get_size returns correct value
         script = FSPythonScript('test1', script_path)
         self.assertEqual(len(script.read()),script.get_size())
 
+    def testInitializationRaceCondition(self):
+        # Tries to exercise a former race condition where
+        # FSObject._updateFromFS() set self._parsed before the
+        # object was really parsed.
+        for n in range(10):
+            f = Folder()
+            script = FSPythonScript('test1', script_path).__of__(f)
+            res = []
+
+            def call_script(script=script, res=res):
+                try:
+                    res.append(script())
+                except:
+                    res.append('%s: %s' % sys.exc_info()[:2])
+
+            start_new_thread(call_script, ())
+            call_script()
+            while len(res) < 2:
+                time.sleep(0.05)
+            self.assertEqual(res, ['test1', 'test1'], res)
+
 def test_suite():
     return TestSuite((
         makeSuite(FSPythonScriptTests),
@@ -20,7 +45,4 @@
 
 if __name__ == '__main__':
     main(defaultTest='test_suite')
-
-
-