You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by st...@apache.org on 2004/12/10 04:09:30 UTC

svn commit: r111461 - /perl/modperl/trunk/t/conf/modperl_extra.pl /perl/modperl/trunk/t/conf/post_config_startup.pl

Author: stas
Date: Thu Dec  9 19:09:28 2004
New Revision: 111461

URL: http://svn.apache.org/viewcvs?view=rev&rev=111461
Log:
move the code that doesn't have to be run at startup phase to the 
post_config phase (have those in a separate file post_config_startup.pl 
which is require()'d by a registered post_config callback

Added:
   perl/modperl/trunk/t/conf/post_config_startup.pl
Modified:
   perl/modperl/trunk/t/conf/modperl_extra.pl

Modified: perl/modperl/trunk/t/conf/modperl_extra.pl
Url: http://svn.apache.org/viewcvs/perl/modperl/trunk/t/conf/modperl_extra.pl?view=diff&rev=111461&p1=perl/modperl/trunk/t/conf/modperl_extra.pl&r1=111460&p2=perl/modperl/trunk/t/conf/modperl_extra.pl&r2=111461
==============================================================================
--- perl/modperl/trunk/t/conf/modperl_extra.pl	(original)
+++ perl/modperl/trunk/t/conf/modperl_extra.pl	Thu Dec  9 19:09:28 2004
@@ -1,64 +1,41 @@
+##########################################################
+### IMPORTANT: only things that must be run absolutely ###
+### during the config phase should be in this file     ###
+##########################################################
+
 use strict;
 use warnings FATAL => 'all';
 
-use Socket (); # test DynaLoader vs. XSLoader workaround for 5.6.x
-use IO::File ();
+die '$ENV{MOD_PERL} not set!' unless $ENV{MOD_PERL};
+
 use File::Spec::Functions qw(canonpath catdir);
 
 use Apache2 ();
 
-use Apache::ServerRec ();
 use Apache::ServerUtil ();
+use Apache::ServerRec ();
 use Apache::Process ();
-use Apache::RequestRec ();
-use Apache::RequestIO ();
-use Apache::RequestUtil ();
-use Apache::Connection ();
 use Apache::Log ();
 
-use APR::Table ();
-use APR::Pool ();
-
-use ModPerl::Util (); #for CORE::GLOBAL::exit
-
-# would be nice to write a real test, but for now just see that we can
-# load it:
-use Apache::SizeLimit ();
-
 use Apache::Const -compile => ':common';
-use APR::Const    -compile => ':common';
 
 reorg_INC();
 
-die '$ENV{MOD_PERL} not set!' unless $ENV{MOD_PERL};
-
-END {
-    warn "END in modperl_extra.pl, pid=$$\n";
-}
+register_post_config_startup();
 
 startup_info();
 
 test_add_config();
 
-test_hooks_startup();
-
-test_method_obj();
-
-test_modperl_env();
-
-test_loglevel();
-
 test_add_version_component();
 
 test_apache_status();
 
-test_apache_resource();
-
-test_perl_ithreads();
-
-test_server_shutdown_cleanup_register();
+test_hooks_startup();
 
+test_modperl_env();
 
+test_method_obj();
 
 ### only subs below this line ###
 
@@ -81,26 +58,16 @@
     @INC = (@a, @b, @c);
 }
 
-sub test_method_obj {
-    # see t/modperl/methodobj
-    use TestModperl::methodobj ();
-    $TestModperl::MethodObj = TestModperl::methodobj->new;
-}
-
-sub test_modperl_env {
-    # see t/response/TestModperl/env.pm
-    $ENV{MODPERL_EXTRA_PL} = __FILE__;
-}
-
-# test startup loglevel setting (under threaded mpms loglevel can be
-# changed only before threads are started) so here we test whether we
-# can still set it after restart
-sub test_loglevel {
-    use Apache::Const -compile => 'LOG_INFO';
+sub register_post_config_startup {
     my $s = Apache->server;
-    my $oldloglevel = $s->loglevel(Apache::LOG_INFO);
-    # restore
-    $s->loglevel($oldloglevel);
+    my $pool = $s->process->pool;
+    my $t_conf_path = Apache::ServerUtil::server_root_relative($pool,
+                                                               "conf");
+
+    # most of the startup code needs to be run at the post_config
+    # phase
+    $s->push_handlers(PerlPostConfigHandler => sub {
+        require "$t_conf_path/post_config_startup.pl"; Apache::OK });
 }
 
 sub startup_info {
@@ -119,7 +86,6 @@
     $server->log->info("base server + $vhosts vhosts ready to run tests");
 }
 
-
 sub test_add_config {
     # testing $s->add_config()
     my $conf = <<'EOC';
@@ -137,18 +103,6 @@
     Apache->server->add_config(['<Perl >', '1;', '</Perl>']);
 }
 
-# cleanup files for TestHooks::startup which can't be done from the
-# test itself because the files are created at the server startup and
-# the test needing these files may run more than once (t/SMOKE)
-sub test_hooks_startup {
-    require Apache::Test;
-    my $dir = catdir Apache::Test::vars('documentroot'), qw(hooks startup);
-    for (<$dir/*>) {
-        my $file = ($_ =~ /(.*(?:open_logs|post_config)-\d+)/);
-        unlink $file;
-    }
-}
-
 sub test_add_version_component {
     Apache->server->push_handlers(
         PerlPostConfigHandler => \&add_my_version);
@@ -173,54 +127,28 @@
     ) if Apache::Module::loaded('Apache::Status');
 }
 
-sub test_apache_resource {
-    ### Apache::Resource tests
-
-    # load first for the menu
-    require Apache::Status;
-
-    # uncomment for local tests
-    #$ENV{PERL_RLIMIT_DEFAULTS} = 1;
-    #$Apache::Resource::Debug   = 1;
-
-    # requires optional BSD::Resource
-    return unless eval { require BSD::Resource };
-
-    require Apache::Resource;
-}
-
-
-sub test_perl_ithreads {
-    # this is needed for TestPerl::ithreads
-    # one should be able to boot ithreads at the server startup and
-    # then access the ithreads setup at run-time when a perl
-    # interpreter is running on a different native threads (testing
-    # that perl interpreters and ithreads aren't related to the native
-    # threads they are running on). This should work starting from
-    # perl-5.8.1 and higher.
-    use Config;
-    if ($] >= 5.008001 && $Config{useithreads}) {
-        eval { require threads; "threads"->import() };
+# cleanup files for TestHooks::startup which can't be done from the
+# test itself because the files are created at the server startup and
+# the test needing these files may run more than once (t/SMOKE)
+sub test_hooks_startup {
+    require Apache::Test;
+    my $dir = catdir Apache::Test::vars('documentroot'), qw(hooks startup);
+    for (<$dir/*>) {
+        my $file = ($_ =~ /(.*(?:open_logs|post_config)-\d+)/);
+        unlink $file;
     }
 }
 
-sub test_server_shutdown_cleanup_register {
-    # we can't really test the functionality since it happens at
-    # server shutdown, when the test suite has finished its run
-    # so just check that we can register the cleanup and that it
-    # doesn't segfault
-    Apache::ServerUtil::server_shutdown_cleanup_register(sub { Apache::OK });
-
-    # replace the sub with the following to get some visual debug
-    # should log cnt:1 on -start, oncand cnt: 2 -stop followed by cnt: 1)
-    #Apache::ServerUtil::server_shutdown_cleanup_register( sub {
-    #    my $cnt = Apache::ServerUtil::restart_count();
-    #    open my $fh, ">>/tmp/out" or die "$!";
-    #    print $fh "cnt: $cnt\n";
-    #    close $fh;
-    #});
+sub test_modperl_env {
+    # see t/response/TestModperl/env.pm
+    $ENV{MODPERL_EXTRA_PL} = __FILE__;
 }
 
+sub test_method_obj {
+    # see t/modperl/methodobj
+    require TestModperl::methodobj;
+    $TestModperl::MethodObj = TestModperl::methodobj->new;
+}
 
 sub ModPerl::Test::add_config {
     my $r = shift;
@@ -229,15 +157,6 @@
     $r->add_config(['require valid-user']);
 
     Apache::OK;
-}
-
-sub ModPerl::Test::exit_handler {
-    my($p, $s) = @_;
-
-    $s->log->info("Child process pid=$$ is exiting");
-
-    Apache::OK;
-
 }
 
 1;

Added: perl/modperl/trunk/t/conf/post_config_startup.pl
Url: http://svn.apache.org/viewcvs/perl/modperl/trunk/t/conf/post_config_startup.pl?view=auto&rev=111461
==============================================================================
--- (empty file)
+++ perl/modperl/trunk/t/conf/post_config_startup.pl	Thu Dec  9 19:09:28 2004
@@ -0,0 +1,114 @@
+##########################################################
+### this file contains code that should be run on the  ###
+### server startup but not during the config phase     ###
+##########################################################
+use strict;
+use warnings FATAL => 'all';
+
+use Socket (); # test DynaLoader vs. XSLoader workaround for 5.6.x
+
+use Apache::ServerRec ();
+use Apache::ServerUtil ();
+use Apache::Process ();
+use Apache::RequestRec ();
+use Apache::RequestIO ();
+use Apache::RequestUtil ();
+use Apache::Connection ();
+use Apache::Log ();
+
+use APR::Table ();
+use APR::Pool ();
+
+use ModPerl::Util (); #for CORE::GLOBAL::exit
+
+# would be nice to write a real test, but for now just see that we can
+# load it:
+use Apache::SizeLimit ();
+
+use Apache::Const -compile => ':common';
+
+END {
+    warn "END in modperl_extra.pl, pid=$$\n";
+}
+
+test_loglevel();
+
+test_apache_resource();
+
+test_perl_ithreads();
+
+test_server_shutdown_cleanup_register();
+
+### only subs below this line ###
+
+
+# test startup loglevel setting (under threaded mpms loglevel can be
+# changed only before threads are started) so here we test whether we
+# can still set it after restart
+sub test_loglevel {
+    use Apache::Const -compile => 'LOG_INFO';
+    my $s = Apache->server;
+    my $oldloglevel = $s->loglevel(Apache::LOG_INFO);
+    # restore
+    $s->loglevel($oldloglevel);
+}
+
+sub test_apache_resource {
+    ### Apache::Resource tests
+
+    # load first for the menu
+    require Apache::Status;
+
+    # uncomment for local tests
+    #$ENV{PERL_RLIMIT_DEFAULTS} = 1;
+    #$Apache::Resource::Debug   = 1;
+
+    # requires optional BSD::Resource
+    return unless eval { require BSD::Resource };
+
+    require Apache::Resource;
+}
+
+
+sub test_perl_ithreads {
+    # this is needed for TestPerl::ithreads
+    # one should be able to boot ithreads at the server startup and
+    # then access the ithreads setup at run-time when a perl
+    # interpreter is running on a different native threads (testing
+    # that perl interpreters and ithreads aren't related to the native
+    # threads they are running on). This should work starting from
+    # perl-5.8.1 and higher.
+    use Config;
+    if ($] >= 5.008001 && $Config{useithreads}) {
+        eval { require threads; "threads"->import() };
+    }
+}
+
+sub test_server_shutdown_cleanup_register {
+    # we can't really test the functionality since it happens at
+    # server shutdown, when the test suite has finished its run
+    # so just check that we can register the cleanup and that it
+    # doesn't segfault
+    Apache::ServerUtil::server_shutdown_cleanup_register(sub { Apache::OK });
+
+    # replace the sub with the following to get some visual debug
+    # should log cnt:1 on -start, oncand cnt: 2 -stop followed by cnt: 1)
+    #Apache::ServerUtil::server_shutdown_cleanup_register( sub {
+    #    my $cnt = Apache::ServerUtil::restart_count();
+    #    open my $fh, ">>/tmp/out" or die "$!";
+    #    print $fh "cnt: $cnt\n";
+    #    close $fh;
+    #});
+}
+
+sub ModPerl::Test::exit_handler {
+    my($p, $s) = @_;
+
+    $s->log->info("Child process pid=$$ is exiting");
+
+    Apache::OK;
+
+}
+
+
+1;

Re: svn commit: r111461 - /perl/modperl/trunk/t/conf/modperl_extra.pl /perl/modperl/trunk/t/conf/post_config_startup.pl

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> stas@apache.org wrote:
> 
>> Author: stas
>> Date: Thu Dec  9 19:09:28 2004
>> New Revision: 111461
>>
>> URL: http://svn.apache.org/viewcvs?view=rev&rev=111461
>> Log:
>> move the code that doesn't have to be run at startup phase to the 
>> post_config phase (have those in a separate file 
>> post_config_startup.pl which is require()'d by a registered 
>> post_config callback
> 
> 
> I see more bizarre problems with trying to load things from post_config, 
> e.g.
> 
>     Apache::Status->menu_item(rlimit => "Resource Limits",
>             \&status_rlimit)
>           if Apache::Module::loaded("Apache::Status");
> 
> is called, when Apache::Resource is loaded, but it never shows up in the 
> Apache::Status menu. So the resource test fails.
> 

The mystery for the problems (caused by the move of parts from startup.pl 
to post_config_startup.pl) was rather simple. We were cloning working perl 
pools in the post_config phase, but user post_config handlers were running 
*after* the modperl's internal callback, that's why the changes weren't 
seen by the workers. Moving that post_config phase to APR_HOOK_REALLY_LAST 
(from _FIRST) solved the problem right away. I'll commit the fix after 
some testing...

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

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


Re: svn commit: r111461 - /perl/modperl/trunk/t/conf/modperl_extra.pl /perl/modperl/trunk/t/conf/post_config_startup.pl

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
>>    Apache::Status->menu_item(rlimit => "Resource Limits",
>>            \&status_rlimit)
>>          if Apache::Module::loaded("Apache::Status");
>>
>>is called, when Apache::Resource is loaded, but it never shows up in the
>>Apache::Status menu. So the resource test fails.
> 
> 
> speaking of which, I just noticed that the server won't start with an
> unthreaded perl - the only error in the log is
> 
> [Fri Dec 10 05:05:12 2004] [error] Undefined subroutine
> &main::/src/mod_perl-2.0/blib/lib/Apache2/Apache/Status.pm called.
> 
> 
> Configuration Failed

Yes, I know, my nightly build has uncovered a few of these. I guess I've 
committed it too early, but it worked with threaded worker just fine. I'm 
trying to figure out what's the difference with running those in the 
post_config phase. If I don't figure out shortly, I'll revert the change 
until it's resolved.

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

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


Re: svn commit: r111461 - /perl/modperl/trunk/t/conf/modperl_extra.pl /perl/modperl/trunk/t/conf/post_config_startup.pl

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>     Apache::Status->menu_item(rlimit => "Resource Limits",
>             \&status_rlimit)
>           if Apache::Module::loaded("Apache::Status");
> 
> is called, when Apache::Resource is loaded, but it never shows up in the
> Apache::Status menu. So the resource test fails.

speaking of which, I just noticed that the server won't start with an
unthreaded perl - the only error in the log is

[Fri Dec 10 05:05:12 2004] [error] Undefined subroutine
&main::/src/mod_perl-2.0/blib/lib/Apache2/Apache/Status.pm called.


Configuration Failed

--Geoff

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


Re: svn commit: r111461 - /perl/modperl/trunk/t/conf/modperl_extra.pl /perl/modperl/trunk/t/conf/post_config_startup.pl

Posted by Stas Bekman <st...@stason.org>.
stas@apache.org wrote:
> Author: stas
> Date: Thu Dec  9 19:09:28 2004
> New Revision: 111461
> 
> URL: http://svn.apache.org/viewcvs?view=rev&rev=111461
> Log:
> move the code that doesn't have to be run at startup phase to the 
> post_config phase (have those in a separate file post_config_startup.pl 
> which is require()'d by a registered post_config callback

I see more bizarre problems with trying to load things from post_config, e.g.

     Apache::Status->menu_item(rlimit => "Resource Limits",
             \&status_rlimit)
           if Apache::Module::loaded("Apache::Status");

is called, when Apache::Resource is loaded, but it never shows up in the 
Apache::Status menu. So the resource test fails.

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

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


Re: svn commit: r111461 - /perl/modperl/trunk/t/conf/modperl_extra.pl /perl/modperl/trunk/t/conf/post_config_startup.pl

Posted by Stas Bekman <st...@stason.org>.
stas@apache.org wrote:
> Author: stas
> Date: Thu Dec  9 19:09:28 2004
> New Revision: 111461
> 
> URL: http://svn.apache.org/viewcvs?view=rev&rev=111461
> Log:
> move the code that doesn't have to be run at startup phase to the 
> post_config phase (have those in a separate file post_config_startup.pl 
> which is require()'d by a registered post_config callback

What I don't understand is why the following patch, which moves seemingly 
unrelated to config code to post_config phase, breaks a bunch of tests. Ideas?

Index: t/conf/modperl_extra.pl
===================================================================
--- t/conf/modperl_extra.pl	(revision 111461)
+++ t/conf/modperl_extra.pl	(working copy)
@@ -35,8 +35,6 @@

  test_modperl_env();

-test_method_obj();
-
  ### only subs below this line ###

  sub reorg_INC {
@@ -144,19 +142,5 @@
      $ENV{MODPERL_EXTRA_PL} = __FILE__;
  }

-sub test_method_obj {
-    # see t/modperl/methodobj
-    require TestModperl::methodobj;
-    $TestModperl::MethodObj = TestModperl::methodobj->new;
-}

-sub ModPerl::Test::add_config {
-    my $r = shift;
-
-    #test adding config at request time
-    $r->add_config(['require valid-user']);
-
-    Apache::OK;
-}
-
  1;
Index: t/conf/post_config_startup.pl
===================================================================
--- t/conf/post_config_startup.pl	(revision 111461)
+++ t/conf/post_config_startup.pl	(working copy)
@@ -39,6 +39,8 @@

  test_server_shutdown_cleanup_register();

+test_method_obj();
+
  ### only subs below this line ###


@@ -111,4 +113,19 @@
  }


+sub test_method_obj {
+    # see t/modperl/methodobj
+    require TestModperl::methodobj;
+    $TestModperl::MethodObj = TestModperl::methodobj->new;
+}
+
+sub ModPerl::Test::add_config {
+    my $r = shift;
+
+    #test adding config at request time
+    $r->add_config(['require valid-user']);
+
+    Apache::OK;
+}
+
  1;



-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: svn commit: r111461 - /perl/modperl/trunk/t/conf/modperl_extra.pl /perl/modperl/trunk/t/conf/post_config_startup.pl

Posted by Stas Bekman <st...@stason.org>.
stas@apache.org wrote:
> Author: stas
> Date: Thu Dec  9 19:09:28 2004
> New Revision: 111461
> 
> URL: http://svn.apache.org/viewcvs?view=rev&rev=111461
> Log:
> move the code that doesn't have to be run at startup phase to the 
> post_config phase (have those in a separate file post_config_startup.pl 
> which is require()'d by a registered post_config callback

What I don't understand is why the following patch, which moves seemingly 
unrelated to config code to post_config phase, breaks a bunch of tests. Ideas?

Index: t/conf/modperl_extra.pl
===================================================================
--- t/conf/modperl_extra.pl	(revision 111461)
+++ t/conf/modperl_extra.pl	(working copy)
@@ -35,8 +35,6 @@

  test_modperl_env();

-test_method_obj();
-
  ### only subs below this line ###

  sub reorg_INC {
@@ -144,19 +142,5 @@
      $ENV{MODPERL_EXTRA_PL} = __FILE__;
  }

-sub test_method_obj {
-    # see t/modperl/methodobj
-    require TestModperl::methodobj;
-    $TestModperl::MethodObj = TestModperl::methodobj->new;
-}

-sub ModPerl::Test::add_config {
-    my $r = shift;
-
-    #test adding config at request time
-    $r->add_config(['require valid-user']);
-
-    Apache::OK;
-}
-
  1;
Index: t/conf/post_config_startup.pl
===================================================================
--- t/conf/post_config_startup.pl	(revision 111461)
+++ t/conf/post_config_startup.pl	(working copy)
@@ -39,6 +39,8 @@

  test_server_shutdown_cleanup_register();

+test_method_obj();
+
  ### only subs below this line ###


@@ -111,4 +113,19 @@
  }


+sub test_method_obj {
+    # see t/modperl/methodobj
+    require TestModperl::methodobj;
+    $TestModperl::MethodObj = TestModperl::methodobj->new;
+}
+
+sub ModPerl::Test::add_config {
+    my $r = shift;
+
+    #test adding config at request time
+    $r->add_config(['require valid-user']);
+
+    Apache::OK;
+}
+
  1;



-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

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