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;

Reply via email to