quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Graham Dumpleton <grah...@dscpl.com.au>
Subject Re: Changes made to apache.register_cleanup()
Date Wed, 08 Mar 2006 10:08:22 GMT
Okay, the reason that the failing code wasn't detected was because
the test searched for the presence of a specific string in the
error log file. Problems was that that string appeared in the
Python exception generated by the incorrect code.

[Wed Mar 08 21:01:12 2006] [notice] mod_python: (Re)importing module  
'tests'
[Wed Mar 08 21:01:13 2006] [error] [client 127.0.0.1] PythonHandler  
tests::apache_register_cleanup: Traceback (most recent call last):
[Wed Mar 08 21:01:13 2006] [error] [client 127.0.0.1] PythonHandler  
tests::apache_register_cleanup:   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/mod_python/apache.py", line 300, in  
HandlerDispatch\n    result = object(req)
[Wed Mar 08 21:01:13 2006] [error] [client 127.0.0.1] PythonHandler  
tests::apache_register_cleanup:   File  
"/Users/grahamd/Workspaces/mod_python-trunk-dev-5/test/htdocs/ 
tests.py", line 844, in apache_register_cleanup\n     
apache.register_cleanup(req.interpreter, req.server, server_cleanup,  
"apache_register_cleanup test ok")
[Wed Mar 08 21:01:13 2006] [error] [client 127.0.0.1] PythonHandler  
tests::apache_register_cleanup: TypeError: register_cleanup() takes at  
most 2 arguments (4 given)

The string in this case was:

   apache_register_cleanup test ok

When you are restructuring the test harnesses, you might be mindful
as to whether there are other situations like this where the log
file is searched for a string. In these situations the string should
not perhaps appear in the actual line that is being tested. Thus instead
of:

def apache_register_cleanup(req):

     apache.register_cleanup(req.interpreter, req.server,  
server_cleanup, "apache_register_cleanup test ok")
     req.write("registered server cleanup that will write to log")

     return apache.OK

Use:

def apache_register_cleanup(req):

     data = "apache_register_cleanup test ok"
     apache.register_cleanup(req.interpreter, req.server,  
server_cleanup, data)
     req.write("registered server cleanup that will write to log")

     return apache.OK

In this case, it would possibly also have been picked up if the response
content was still checked to see if it matched what was written. Ie.,  
the
other string:

   "registered server cleanup that will write to log

Anyway, I'll fix this all up as am going to do some stuff to fix at  
least
the Py_Finalize() issue anyway, so working in related code.

Graham

On 08/03/2006, at 8:50 PM, Graham Dumpleton wrote:

> Nicolas
>
> A while back you made the following change:
>
> r378072 | nlehuen | 2006-02-16 06:41:25 +1100 (Thu, 16 Feb 2006) | 5  
> lines
>
> - Fixed the unit tests for apache.register_cleanup  
> server.register_cleanup. Ther
> e is not way it could have passed before, yet it did ???
> - Corrected the documentation about those two functions, it was badly  
> broken.
> - Added a warning so that users don't try to pass a request object as  
> the argume
> nt to the callable.
>
> You say that you don't understand how old test failed, but I don't
> understand how the new test wouldn't fail.
>
> The apache.register_cleanup() function is defined as:
>
>   def register_cleanup(handler,data=None):
>       _apache.register_cleanup(_interpreter,_server,handler,data)
>
> Ie., the visible method takes two arguments. You changed the test to
> call it with 4.
>
> def apache_register_cleanup(req):
>
>     apache.register_cleanup(req.interpreter, req.server,  
> server_cleanup, "apache_register_cleanup test ok")
>     req.write("registered server cleanup that will write to log")
>
>     return apache.OK
>
> It is only the hidden version of register_cleanup() in the _apache
> module which takes 4.
>
> As a result, the changes made to the documentation aren't correct  
> either.
>
> I'll try and work out why the test harness doesn't fail with code as  
> now
> written, although it is probably all academic given that as described
> in MODPYTHON-109, the server based register cleanup functions will not
> reliably run anyway.
>
> Most strange.
>
> Graham


Mime
View raw message