I'm getting a unit test failure.

FAIL: test_publisher_cache (__main__.PerRequestTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test.py", line 1836, in test_publisher_cache
    self.fail(
  File "/usr/lib/python2.3/unittest.py", line 270, in fail
    raise self.failureException, msg
AssertionError: The publisher cache has reloaded a published module even though it wasn't modified !


Although it's not related to the failure I'd avoid the use of time.clock() in the test function as the behaviour is different on Windows and UNIX, which always makes me nervous. I'd prefer a simple time.time().

I'm investigating the failure now.

Jim

[EMAIL PROTECTED] wrote:
Author: nlehuen
Date: Wed Feb  1 21:17:13 2006
New Revision: 374257

URL: http://svn.apache.org/viewcvs?rev=374257&view=rev
Log:
Changed the mod_python.cache.FileCache.check() method so that it stat() then 
open() the file, rather than open() it and fstat() it. Added a unit test to 
check whether the publisher cache is doing his job correctly.

Modified:
    httpd/mod_python/trunk/lib/python/mod_python/cache.py
    httpd/mod_python/trunk/test/test.py

Modified: httpd/mod_python/trunk/lib/python/mod_python/cache.py
URL: 
http://svn.apache.org/viewcvs/httpd/mod_python/trunk/lib/python/mod_python/cache.py?rev=374257&r1=374256&r2=374257&view=diff
==============================================================================
--- httpd/mod_python/trunk/lib/python/mod_python/cache.py (original)
+++ httpd/mod_python/trunk/lib/python/mod_python/cache.py Wed Feb  1 21:17:13 
2006
@@ -23,7 +23,7 @@
 # Loads Python 2.2 compatibility module
 from python22 import *
-from os import fstat
+from os import stat
 from time import time, mktime
 from rfc822 import parsedate
 from calendar import timegm
@@ -254,19 +254,16 @@
         self.mode=mode
def check(self, key, name, entry):
-        opened = file(key, self.mode)
-
-        timestamp = fstat(opened.fileno())[-2]
+ timestamp = stat(key).st_mtime if entry._value is NOT_INITIALIZED:
             entry._timestamp = timestamp
-            return opened
+            return file(key, self.mode)
         else:
             if entry._timestamp != timestamp:
                 entry._timestamp = timestamp
-                return opened
+                return file(key, self.mode)
             else:
-                opened.close()
                 return None
def build(self, key, name, opened, entry):
@@ -380,7 +377,7 @@
             opened.close()
class HttpModuleCache(HTTPCache):
-    """ A module cache. Give it a file name, it returns a module
+    """ A module cache. Give it an HTTP URL, it returns a module
         which results from the execution of the Python script it contains.
         This module is not inserted into sys.modules.
     """

Modified: httpd/mod_python/trunk/test/test.py
URL: 
http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/test.py?rev=374257&r1=374256&r2=374257&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/test.py (original)
+++ httpd/mod_python/trunk/test/test.py Wed Feb  1 21:17:13 2006
@@ -1803,6 +1803,62 @@
         if (rsp != "test traversable instance ok"):
             self.fail(`rsp`)
+ def test_publisher_cache_conf(self):
+        c = VirtualHost("*",
+                        ServerName("test_publisher"),
+                        DocumentRoot(DOCUMENT_ROOT),
+                        Directory(DOCUMENT_ROOT,
+                                  SetHandler("mod_python"),
+                                  PythonHandler("mod_python.publisher"),
+                                  PythonDebug("On")))
+        return str(c)
+ + def test_publisher_cache(self):
+        print "\n  * Testing mod_python.publisher cache"
+ + def write_published():
+            published = file('htdocs/temp.py','wb')
+            published.write('import time\n')
+            published.write('LOAD_TIME = time.clock()\n')
+            published.write('def index(req):\n')
+            published.write('    return "OK %f"%LOAD_TIME\n')
+            published.close()
+ + write_published()
+        try:
+            rsp = self.vhost_get("test_publisher", path="/temp.py")
+ + if not rsp.startswith('OK '):
+                self.fail(`rsp`)
+ + rsp2 = self.vhost_get("test_publisher", path="/temp.py")
+            if rsp != rsp2:
+                self.fail(
+                    "The publisher cache has reloaded a published module"
+                    " even though it wasn't modified !"
+                )
+ + # We wait three seconds to be sure we won't be annoyed
+            # by any lack of resolution of the stat().st_mtime member.
+            time.sleep(3)
+            write_published()
+ + rsp2 = self.vhost_get("test_publisher", path="/temp.py")
+            if rsp == rsp2:
+                self.fail(
+                    "The publisher cache has not reloaded a published module"
+                    " even though it was modified !"
+                )
+ + rsp = self.vhost_get("test_publisher", path="/temp.py")
+            if rsp != rsp2:
+                self.fail(
+                    "The publisher cache has reloaded a published module"
+                    " even though it wasn't modified !"
+                )
+ finally: + os.remove('htdocs/temp.py')
+
 class PerInstanceTestCase(unittest.TestCase, HttpdCtrl):
     # this is a test case which requires a complete
     # restart of httpd (e.g. we're using a fancy config)
@@ -1916,6 +1972,7 @@
         perRequestSuite.addTest(PerRequestTestCase("test_publisher_security"))
         # 
perRequestSuite.addTest(PerRequestTestCase("test_publisher_iterator"))
         perRequestSuite.addTest(PerRequestTestCase("test_publisher_hierarchy"))
+        perRequestSuite.addTest(PerRequestTestCase("test_publisher_cache"))
         # this must be last so its error_log is not overwritten
         perRequestSuite.addTest(PerRequestTestCase("test_internal"))


Reply via email to