[svn:modperl-modules] rev 134 - in Apache-Scoreboard-1.0/trunk: . t t/conf t/external t/internal t/lib t/lib/MyTest t/response t/response/TestInternal
[email protected] 5 Feb 2005 03:24:36 -0000
| Newsgroups | perl.modperl.modules.svn |
|---|---|
| Message-ID | <[email protected]> |
Author: stas
Date: Fri Feb 4 19:24:35 2005
New Revision: 134
Added:
Apache-Scoreboard-1.0/trunk/t/
Apache-Scoreboard-1.0/trunk/t/TEST.PL (contents, props changed)
Apache-Scoreboard-1.0/trunk/t/conf/
Apache-Scoreboard-1.0/trunk/t/conf/extra.conf.in
Apache-Scoreboard-1.0/trunk/t/conf/extra.last.conf.in
Apache-Scoreboard-1.0/trunk/t/conf/modperl_extra.pl
Apache-Scoreboard-1.0/trunk/t/external/
Apache-Scoreboard-1.0/trunk/t/external/basic.t (contents, props changed)
Apache-Scoreboard-1.0/trunk/t/internal/
Apache-Scoreboard-1.0/trunk/t/internal/basic.t (contents, props changed)
Apache-Scoreboard-1.0/trunk/t/lib/
Apache-Scoreboard-1.0/trunk/t/lib/MyTest/
Apache-Scoreboard-1.0/trunk/t/lib/MyTest/Common.pm (contents, props changed)
Apache-Scoreboard-1.0/trunk/t/response/
Apache-Scoreboard-1.0/trunk/t/response/TestInternal/
Apache-Scoreboard-1.0/trunk/t/response/TestInternal/basic.pm (contents, props changed)
Modified:
Apache-Scoreboard-1.0/trunk/Changes
Log:
added a live test suite
Modified: Apache-Scoreboard-1.0/trunk/Changes
==============================================================================
--- Apache-Scoreboard-1.0/trunk/Changes (original)
+++ Apache-Scoreboard-1.0/trunk/Changes Fri Feb 4 19:24:35 2005
@@ -1,5 +1,6 @@
0.14 -
+added a live test suite
0.13 - Fri Jan 21 21:00:23 EST 2005
Added: Apache-Scoreboard-1.0/trunk/t/TEST.PL
==============================================================================
--- (empty file)
+++ Apache-Scoreboard-1.0/trunk/t/TEST.PL Fri Feb 4 19:24:35 2005
@@ -0,0 +1,36 @@
+#!perl
+
+use strict;
+use warnings FATAL => 'all';
+
+use lib qw(t/lib lib ../Apache-Test/lib);
+
+MyTest->new->run(@ARGV);
+
+# sub-class Apache::TestRunPerl
+package MyTest;
+
+use base qw(Apache::TestRunPerl);
+
+# have a few servers to have better testing
+use constant MIN_CLIENTS => 3;
+
+# subclass new_test_config to add some config vars which will be
+# replaced in generated httpd.conf
+sub new_test_config {
+ my $self = shift;
+
+ $self->{conf_opts}->{minclients} ||= MIN_CLIENTS;
+
+ return $self->SUPER::new_test_config;
+}
+
+sub bug_report {
+ my $self = shift;
+
+ print <<EOI;
++--------------------------------------------------------+
+| Please file a bug report: http://perl.apache.org/bugs/ |
++--------------------------------------------------------+
+EOI
+}
Added: Apache-Scoreboard-1.0/trunk/t/conf/extra.conf.in
==============================================================================
--- (empty file)
+++ Apache-Scoreboard-1.0/trunk/t/conf/extra.conf.in Fri Feb 4 19:24:35 2005
@@ -0,0 +1,9 @@
+# make sure that we test under Taint mode
+PerlTaintCheck On
+PerlWarn On
+
+<IfModule mod_status.c>
+ # XXX: can try to loadmodule mod_status if it's not loaded and DSO
+ ExtendedStatus On
+</IfModule>
+
Added: Apache-Scoreboard-1.0/trunk/t/conf/extra.last.conf.in
==============================================================================
--- (empty file)
+++ Apache-Scoreboard-1.0/trunk/t/conf/extra.last.conf.in Fri Feb 4 19:24:35 2005
@@ -0,0 +1,6 @@
+
+PerlModule Apache::Scoreboard
+<Location /scoreboard>
+ SetHandler perl-script
+ PerlHandler Apache::Scoreboard::send
+</Location>
Added: Apache-Scoreboard-1.0/trunk/t/conf/modperl_extra.pl
==============================================================================
--- (empty file)
+++ Apache-Scoreboard-1.0/trunk/t/conf/modperl_extra.pl Fri Feb 4 19:24:35 2005
@@ -0,0 +1,5 @@
+unless ($ENV{MOD_PERL}) {
+ die '$ENV{MOD_PERL} not set!';
+}
+
+1;
Added: Apache-Scoreboard-1.0/trunk/t/external/basic.t
==============================================================================
--- (empty file)
+++ Apache-Scoreboard-1.0/trunk/t/external/basic.t Fri Feb 4 19:24:35 2005
@@ -0,0 +1,32 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings FATAL => 'all';
+
+local $| = 1;
+
+use MyTest::Common ();
+
+use Apache::Test;
+use Apache::TestRequest ();
+use Apache::TestTrace;
+
+use File::Spec::Functions qw(catfile);
+
+my $tests_local = 0;
+my $tests_common = MyTest::Common::num_of_tests();
+
+plan tests => $tests_local + $tests_common;
+
+my $cfg = Apache::Test::config();
+my $vars = $cfg->{vars};
+
+my $store_file = catfile $vars->{documentroot}, "scoreboard";
+my $hostport = Apache::TestRequest::hostport($cfg);
+my $retrieve_url = "http://$hostport/scoreboard";
+
+my $image = Apache::Scoreboard->fetch($retrieve_url);
+
+die "no image fetched" unless $image;
+
+MyTest::Common::test($image);
Added: Apache-Scoreboard-1.0/trunk/t/internal/basic.t
==============================================================================
--- (empty file)
+++ Apache-Scoreboard-1.0/trunk/t/internal/basic.t Fri Feb 4 19:24:35 2005
@@ -0,0 +1,9 @@
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::TestRequest;
+
+# a dummy request to / to get the scoreboard counters going
+my $discard = GET_BODY "/index.html";
+
+print GET_BODY_ASSERT "/TestInternal__basic";
Added: Apache-Scoreboard-1.0/trunk/t/lib/MyTest/Common.pm
==============================================================================
--- (empty file)
+++ Apache-Scoreboard-1.0/trunk/t/lib/MyTest/Common.pm Fri Feb 4 19:24:35 2005
@@ -0,0 +1,83 @@
+package MyTest::Common;
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Scoreboard;
+
+use Apache::Test;
+use Apache::TestUtil;
+use Apache::TestTrace;
+
+sub num_of_tests {
+ return 5;
+}
+
+sub test {
+ my $image = shift;
+
+ {
+ t_debug "constants";
+ ok Apache::Constants::HARD_SERVER_LIMIT;
+ ok Apache::Scoreboard::REMOTE_SCOREBOARD_TYPE;
+ }
+
+ # quick check
+ ok image_is_ok($image);
+
+ my $ok = 1;
+ for (my $parent = $image->parent; $parent; $parent = $parent->next) {
+
+ my $ok = 1;
+ next if score_is_ok($parent);
+
+ die "failed score check for pid: " . $parent->pid;
+ }
+
+ ok $ok;
+
+ my $pids = $image->pids;
+ error $pids;
+ ok @$pids;
+}
+
+my @methods = qw(status access_count request client
+ bytes_served conn_bytes conn_count times start_time
+ stop_time req_time);
+
+# vhost is not available outside mod_perl, since it requires a call to
+# an Apache method
+push @methods, "vhost" if $ENV{MOD_PERL};
+
+sub score_is_ok {
+ my $parent = shift;
+
+ my $ok = 1;
+ $ok = 0 unless $parent->pid;
+
+ my $server = $parent->server; # Apache::ServerScore object
+ for (@methods) {
+ no strict 'refs';
+ my $val = $server->$_;
+ #error "$_ [$val]";
+ $ok = 0 unless defined $val;
+ }
+
+ return $ok;
+}
+
+# try to access various underlying datastructures to test that the
+# image is valid
+sub image_is_ok {
+ my ($image) = shift;
+ my $status = 1;
+ $status = 0 unless $image &&
+ ref($image) eq 'Apache::Scoreboard' &&
+ $image->pids &&
+ $image->servers(0) &&
+ $image->parent(0)->pid;
+
+ return $status;
+}
+
+1;
Added: Apache-Scoreboard-1.0/trunk/t/response/TestInternal/basic.pm
==============================================================================
--- (empty file)
+++ Apache-Scoreboard-1.0/trunk/t/response/TestInternal/basic.pm Fri Feb 4 19:24:35 2005
@@ -0,0 +1,40 @@
+package TestInternal::basic;
+
+use Apache::Test;
+use Apache::TestRequest ();
+use Apache::TestTrace;
+
+use File::Spec::Functions qw(catfile);
+
+use Apache::Scoreboard ();
+use MyTest::Common ();
+
+use Apache::Constants qw(:common);
+
+my $tests_local = 0;
+my $tests_common = MyTest::Common::num_of_tests();
+
+my $store_file = catfile $vars->{documentroot}, "scoreboard";
+my $hostport = Apache::TestRequest::hostport($cfg);
+my $retrieve_url = "http://$hostport/scoreboard";
+
+sub handler {
+ my $r = shift;
+
+ plan $r, tests => $tests_local + $tests_common*2;
+
+ my $cfg = Apache::Test::config();
+ my $vars = $cfg->{vars};
+
+ my @images = (
+ Apache::Scoreboard->fetch($retrieve_url),
+ Apache::Scoreboard->image(),
+ );
+
+ for my $image (@images) {
+ die "no image fetched" unless $image;
+ MyTest::Common::test($image);
+ }
+
+ return OK;
+}