You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Geoffrey Young <gy...@laserlink.net> on 2001/08/10 22:34:26 UTC

strange TestServer error

ok, with the recent test suite I wasn't able to get past a strange error:

Use of uninitialized value in numeric ge (>=) at
Apache-Test/lib/Apache/TestServer.pm line 364.


Index: Apache-Test/lib/Apache/TestServer.pm
===================================================================
RCS file:
/home/cvspublic/httpd-test/perl-framework/Apache-Test/lib/Apache/TestServer.
pm,v
retrieving revision 1.17
diff -u -r1.17 TestServer.pm
--- Apache-Test/lib/Apache/TestServer.pm        2001/08/07 00:24:33     1.17
+++ Apache-Test/lib/Apache/TestServer.pm        2001/08/10 20:24:26
@@ -360,17 +360,17 @@
         sleep 1;
     }
 
-    for (1..$tries) {
+    for my $try (1..$tries) {
         if ($server_up->()) {
             print "ok\n";
             return 1;
         }
-        elsif ($_ >= $tries) {
+        elsif ($try >= $tries) {
             print "giving up\n";
         }
         else {
             print "...";
-            sleep $_;
+            sleep $try;
         }
     }

looks trivial, I know, but I few debugging test showed that something was
undef'ing $_ between the
if ($server_up->()) {

and

elsif ($_ >= $tries) {

I don't have the time this afternoon to trace it, but I was getting a bunch
of malformed errors when I turned off the local $SIG(__WARN__} stuff...

anyway, for what it's worth...

--Geoff

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: strange TestServer error

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:

> ok, with the recent test suite I wasn't able to get past a strange error:
> 
> Use of uninitialized value in numeric ge (>=) at
> Apache-Test/lib/Apache/TestServer.pm line 364.
> 
> 
> Index: Apache-Test/lib/Apache/TestServer.pm
> ===================================================================
> RCS file:
> /home/cvspublic/httpd-test/perl-framework/Apache-Test/lib/Apache/TestServer.
> pm,v
> retrieving revision 1.17
> diff -u -r1.17 TestServer.pm
> --- Apache-Test/lib/Apache/TestServer.pm        2001/08/07 00:24:33     1.17
> +++ Apache-Test/lib/Apache/TestServer.pm        2001/08/10 20:24:26
> @@ -360,17 +360,17 @@
>          sleep 1;
>      }
>  
> -    for (1..$tries) {
> +    for my $try (1..$tries) {
>          if ($server_up->()) {
>              print "ok\n";
>              return 1;
>          }
> -        elsif ($_ >= $tries) {
> +        elsif ($try >= $tries) {
>              print "giving up\n";
>          }
>          else {
>              print "...";
> -            sleep $_;
> +            sleep $try;
>          }
>      }
> 
> looks trivial, I know, but I few debugging test showed that something was
> undef'ing $_ between the
> if ($server_up->()) {
> 
> and
> 
> elsif ($_ >= $tries) {
> 
> I don't have the time this afternoon to trace it, but I was getting a bunch
> of malformed errors when I turned off the local $SIG(__WARN__} stuff...


It's usually a bad idea to use $_ in loops that call any other subs, and 
you cannot be sure that they localize $_ before using it. So your fix is 
just fine.

This is one of the questions I usually ask at the interviews.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: using the $Apache::TestRequest::Module global in tests

Posted by Doug MacEachern <do...@covalent.net>.
On Sun, 12 Aug 2001, Stas Bekman wrote:
 
> But why do you need to preserve the value of $Apache::TestRequest::Module
> and restore it once modified?

see Apache::TestRequest::vhost_socket for example.
 
> is it possible to add a function Apache::TestRequest::module and to use
> some function attribute to mark it to be aware of the scope and work like
> local(), i.e. rollback the setting at the end of the scope. This approach
> avoids using a global var, while is still keeping GET-like functions' API
> simple.

why reinvent local?  there's no reason not to use a global variable
here.  and a grand total of one .t test references that global, if we
really need 'hide' this global its not going to be a big deal to change
it.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: using the $Apache::TestRequest::Module global in tests

Posted by Stas Bekman <st...@stason.org>.
On Sat, 11 Aug 2001, Doug MacEachern wrote:

> On Sat, 11 Aug 2001, Stas Bekman wrote:
>
> > Doug,
> >
> > is there any reason for using the localized $Apache::TestRequest::Module
> > in tests, instead of explicit set() call or similar? I thought we were
> > supposed to keep mod_perl super clean. Using globals across modules
> > doesn't seem to be very clean?   Do I miss something? Or does
> > Apache-Test doesn't fall under the mod_perl category's cleanness?
>
> local $Apache::TestRequest::Module = ...; is cleaner than
>
> my $old_module = Apache::TestRequest::module();
> Apache::TestRequest::module($new_module);
> ...
> Apache::TestRequest::module($old_module);

true, I didn't realize that you always want to set back the old module
name. Of course it makes sense then.

But why do you need to preserve the value of $Apache::TestRequest::Module
and restore it once modified?

is it possible to add a function Apache::TestRequest::module and to use
some function attribute to mark it to be aware of the scope and work like
local(), i.e. rollback the setting at the end of the scope. This approach
avoids using a global var, while is still keeping GET-like functions' API
simple.

> in reality, tests that modify $Apache::TestRequest::Module don't even
> need the 'local' (its just habit).  we use a global because the
> Apache::TestRequest functions (GET, GET_RC, POST_BODY, etc) are
> designed to be as terse as possible for ease of use.  using globals
> contributes to the ease of use.  its only in the 'core' libmodperl.so
> and things like Apache::Registry where we insist on clean over ease of
> use api.

ok 1 :)


_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:stas@stason.org   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: using the $Apache::TestRequest::Module global in tests

Posted by Doug MacEachern <do...@covalent.net>.
On Sat, 11 Aug 2001, Stas Bekman wrote:

> Doug,
> 
> is there any reason for using the localized $Apache::TestRequest::Module 
> in tests, instead of explicit set() call or similar? I thought we were 
> supposed to keep mod_perl super clean. Using globals across modules 
> doesn't seem to be very clean?   Do I miss something? Or does 
> Apache-Test doesn't fall under the mod_perl category's cleanness?

local $Apache::TestRequest::Module = ...; is cleaner than

my $old_module = Apache::TestRequest::module();
Apache::TestRequest::module($new_module);
...
Apache::TestRequest::module($old_module);

in reality, tests that modify $Apache::TestRequest::Module don't even need
the 'local' (its just habit).  we use a global because the
Apache::TestRequest functions (GET, GET_RC, POST_BODY, etc) are designed
to be as terse as possible for ease of use.  using globals contributes to
the ease of use.  its only in the 'core' libmodperl.so and things like
Apache::Registry where we insist on clean over ease of use api.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


using the $Apache::TestRequest::Module global in tests

Posted by Stas Bekman <st...@stason.org>.
Doug,

is there any reason for using the localized $Apache::TestRequest::Module 
in tests, instead of explicit set() call or similar? I thought we were 
supposed to keep mod_perl super clean. Using globals across modules 
doesn't seem to be very clean?   Do I miss something? Or does 
Apache-Test doesn't fall under the mod_perl category's cleanness?

Not a rant, but just trying to understand what's the best way to code 
for mod_perl and sometimes things don't make sense to me ;-)

--Stas



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: strange TestServer error

Posted by Doug MacEachern <do...@covalent.net>.
On Fri, 10 Aug 2001, Geoffrey Young wrote:

> ok, with the recent test suite I wasn't able to get past a strange error:
> 
> Use of uninitialized value in numeric ge (>=) at
> Apache-Test/lib/Apache/TestServer.pm line 364.

thanks, sorry for not getting this in sooner.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org