stas 01/10/18 23:52:57 Modified: ModPerl-Registry/t closure.t Log: - port the test to work with same interpteter setup; now the test passes with more than 1 interpreter as well Revision Changes Path 1.4 +37 -30 modperl-2.0/ModPerl-Registry/t/closure.t Index: closure.t =================================================================== RCS file: /home/cvs/modperl-2.0/ModPerl-Registry/t/closure.t,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- closure.t 2001/10/17 05:34:38 1.3 +++ closure.t 2001/10/19 06:52:57 1.4 @@ -2,12 +2,16 @@ use warnings FATAL => 'all'; use Apache::Test; -use File::Spec::Functions; use Apache::TestUtil; +use Apache::TestRequest; +use File::Spec::Functions; # this test tests how various registry packages cache and flush the # scripts their run, and whether they check modification on the disk -# or not +# or not. We don't test the closure side effect, but we use it as a +# test aid. The tests makes sure that they run through the same +# interpreter all the time (in case that the server is running more +# than one interpreter) my @modules = qw(registry registry_ng registry_bb perlrun); @@ -27,15 +31,16 @@ # always flush # no cache - my $url = "/perlrun/$file"; + my $url = "/same_interp/perlrun/$file"; + my $same_interp = Apache::TestRequest::same_interp_tie($url); # should be no closure effect, always returns 1 - my $first = $cfg->http_raw_get($url); - my $second = $cfg->http_raw_get($url); + my $first = req($same_interp, $url); + my $second = req($same_interp, $url); ok t_cmp( 0, - $second - $first, - "never a closure problem", + $first && $second && ($second - $first), + "never the closure problem", ); # modify the file @@ -44,78 +49,73 @@ # it doesn't matter, since the script is not cached anyway ok t_cmp( 1, - $cfg->http_raw_get($url), - "never a closure problem", + req($same_interp, $url), + "never the closure problem", ); } - - { # ModPerl::Registry # no flush # cache, but reload on modification - my $url = "/registry/$file"; + my $url = "/same_interp/registry/$file"; + my $same_interp = Apache::TestRequest::same_interp_tie($url); # we don't know what other test has called this uri before, so we # check the difference between two subsequent calls. In this case # the difference should be 1. - my $first = $cfg->http_raw_get($url); - my $second = $cfg->http_raw_get($url); + my $first = req($same_interp, $url); + my $second = req($same_interp, $url); ok t_cmp( 1, $second - $first, - "closure problem should exist", + "the closure problem should exist", ); # modify the file sleep_and_touch_file($path); - # should no notice closure effect on first request + # should no notice closure effect on the first request ok t_cmp( 1, - $cfg->http_raw_get($url), + req($same_interp, $url), "no closure on the first request", ); } - - - { # ModPerl::RegistryBB # no flush # cache once, don't check for mods - my $url = "/registry_bb/$file"; + my $url = "/same_interp/registry_bb/$file"; + my $same_interp = Apache::TestRequest::same_interp_tie($url); # we don't know what other test has called this uri before, so we # check the difference between two subsequent calls. In this case - # the difference should be 0. - my $first = $cfg->http_raw_get($url); - my $second = $cfg->http_raw_get($url); + # the difference should be 1. + my $first = req($same_interp, $url); + my $second = req($same_interp, $url); ok t_cmp( 1, $second - $first, - "closure problem should exist", + "the closure problem should exist", ); # modify the file sleep_and_touch_file($path); - # - my $third = $cfg->http_raw_get($url); + # modification shouldn't be noticed + my $third = req($same_interp, $url); ok t_cmp( 1, $third - $second, - "no reload on mod, closure persist", + "no reload on mod, the closure problem persists", ); } - - sub sleep_and_touch_file { my $file = shift; # need to wait at least 1 whole sec, so -M will notice the @@ -124,4 +124,11 @@ select undef, undef, undef, 1.00; # sure 1 sec my $now = time; utime $now, $now, $file; +} + +sub req { + my($same_interp, $url) = @_; + my $res = Apache::TestRequest::same_interp_do($same_interp, + \&GET, $url); + return $res ? $res->content : undef; }