From: des Date: Wed, 13 Jun 2007 11:26:09 +0000 (+0000) Subject: Remove the "magic" StartChild, StopChild and LoadVCL test cases. Instead, X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b639f4911c2543a85f0233b3d27cb9ad7376d895;p=varnish Remove the "magic" StartChild, StopChild and LoadVCL test cases. Instead, Case.pm now has init() and fini() (which can of course be overloaded by individual test classes) which start / stop the child, and load a VCL script if the particular test class being run provides one. In addition, fini() will revert to the initial VCL script ("boot") if a custom script was loaded by init(). git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1512 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-tools/regress/lib/Varnish/Test.pm b/varnish-tools/regress/lib/Varnish/Test.pm index 3fb590f2..a631c13f 100644 --- a/varnish-tools/regress/lib/Varnish/Test.pm +++ b/varnish-tools/regress/lib/Varnish/Test.pm @@ -70,9 +70,6 @@ package Varnish::Test; use Carp 'croak'; use Varnish::Test::Engine; -use Varnish::Test::Case::LoadVCL; -use Varnish::Test::Case::StartChild; -use Varnish::Test::Case::StopChild; sub new($) { my ($this) = @_; @@ -85,7 +82,7 @@ sub start_engine($;@) { my ($self, @args) = @_; return if defined $self->{'engine'}; - $self->{'engine'} = Varnish::Test::Engine->new(@args); + $self->{'engine'} = Varnish::Test::Engine->new(@args); $self->{'engine'}->run_loop; } @@ -109,14 +106,9 @@ sub run_case($$) { push(@{$self->{'cases'}}, $case); - Varnish::Test::Case::LoadVCL->new($self->{'engine'})->run($case->vcl) - if $case->can('vcl'); - - Varnish::Test::Case::StartChild->new($self->{'engine'})->run; - + $case->init; $case->run; - - Varnish::Test::Case::StopChild->new($self->{'engine'})->run; + $case->fini; $self->stop_engine; } diff --git a/varnish-tools/regress/lib/Varnish/Test/Case.pm b/varnish-tools/regress/lib/Varnish/Test/Case.pm index c4d188e7..93332b29 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case.pm @@ -54,16 +54,59 @@ sub log($$) { $self->{'engine'}->log($self, 'CAS: ', $str); } -sub run($;@) { - my ($self, @args) = @_; +sub init($) { + my ($self) = @_; $self->{'engine'}->{'case'} = $self; + my $varnish = $self->{'engine'}->{'varnish'}; + + # Load VCL script if we have one + no strict 'refs'; + if (${ref($self)."::VCL"}) { + my $vcl = $varnish->backend_block('main') . ${ref($self)."::VCL"}; + + $varnish->send_vcl(ref($self), $vcl); + $self->run_loop(); + $varnish->use_vcl(ref($self)); + $self->run_loop(); + } + + # Start the child + $varnish->start_child(); + $self->run_loop(); +} + +sub fini($) { + my ($self) = @_; + + my $varnish = $self->{'engine'}->{'varnish'}; + + # Stop the worker process + $varnish->stop_child(); + $self->run_loop(); + + # Revert to initial VCL script + no strict 'refs'; + if (${ref($self)."::VCL"}) { + $varnish->use_vcl('boot'); + $self->run_loop(); + } + + delete $self->{'engine'}->{'case'}; +} + +sub run($;@) { + my ($self, @args) = @_; + $self->log('Starting ' . ref($self)); no strict 'refs'; - foreach my $method (keys %{ref($self) . '::'}) { - next unless $method =~ m/^test([A-Z]\w+)/; + my @tests = @{ref($self)."::TESTS"}; + if (!@tests) { + @tests = sort grep {/^test(\w+)/} (keys %{ref($self) . '::'}); + } + foreach my $method (@tests) { eval { $self->{'count'} += 1; my $result = $self->$method(@args); @@ -77,8 +120,6 @@ sub run($;@) { $self->{'count'}, $method, $@)); } } - - delete $self->{'engine'}->{'case'}; } sub run_loop($) { @@ -99,6 +140,12 @@ sub new_client($) { return Varnish::Test::Client->new($self->{'engine'}); } +sub ev_varnish_command_ok($) { + my ($self) = @_; + + $self->pause_loop; +} + sub ev_client_response($$$) { my ($self, $client, $response) = @_; diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm b/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm deleted file mode 100644 index 0ddcd6e2..00000000 --- a/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer -# in this position and unchanged. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# $Id$ -# - -package Varnish::Test::Case::LoadVCL; - -use strict; -use base 'Varnish::Test::Case'; - -use Carp 'croak'; - -sub testLoadVCL($$) { - my ($self, $vcl) = @_; - - $self->{'engine'}->{'varnish'}->send_vcl('main', $vcl); - $self->run_loop; - - $self->{'engine'}->{'varnish'}->send_command('vcl.use main'); - $self->run_loop; -} - -sub ev_varnish_command_ok($) { - my ($self) = @_; - - $self->pause_loop; -} - -1; diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm b/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm deleted file mode 100644 index 66896d80..00000000 --- a/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer -# in this position and unchanged. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# $Id$ -# - -package Varnish::Test::Case::StartChild; - -use strict; -use base 'Varnish::Test::Case'; - -use Carp 'croak'; - -sub testStartChild($$) { - my ($self, $vcl) = @_; - - $self->{'engine'}->{'varnish'}->start_child; - croak 'Inappropriate event' if $self->run_loop ne 'Started'; - return 'OK'; -} - -sub ev_varnish_child_started($) { - my ($self) = @_; - - $self->pause_loop('Started'); -} - -1; diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm b/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm deleted file mode 100644 index 32efca88..00000000 --- a/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/perl -Tw -#- -# Copyright (c) 2006 Linpro AS -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer -# in this position and unchanged. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# $Id$ -# - -package Varnish::Test::Case::StopChild; - -use strict; -use base 'Varnish::Test::Case'; - -use Carp 'croak'; - -sub testStopChild($$) { - my ($self, $vcl) = @_; - - $self->{'engine'}->{'varnish'}->stop_child; - croak 'Inappropriate event' if $self->run_loop ne 'Stopped'; - return 'OK'; -} - -sub ev_varnish_child_stopped($) { - my ($self) = @_; - - $self->pause_loop('Stopped'); -} - -1; diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm b/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm index b3360dad..c68632ef 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm @@ -35,6 +35,12 @@ use base 'Varnish::Test::Case'; use Carp 'croak'; +our $VCL = " +sub vcl_recv { + pass; +} +"; + sub testVersionMatch($) { my ($self) = @_; @@ -85,14 +91,4 @@ sub ev_server_request($$$$) { $connection->shutdown; } -sub vcl($) { - my ($self) = @_; - - return $self->{'engine'}->{'varnish'}->backend_block('main') . <<'EOVCL' -sub vcl_recv { - pass; -} -EOVCL -} - 1; diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm b/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm index 0d738e4f..bb9921f2 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm @@ -35,6 +35,15 @@ use base 'Varnish::Test::Case'; use Carp 'croak'; +our $VCL = <send_response($response); } -sub vcl($) { - my ($self) = @_; - - return $self->{'engine'}->{'varnish'}->backend_block('main') . <<'EOVCL' -sub vcl_recv { - if (req.request == "POST" && - (!req.http.content-length || req.http.content-length == "0")) { - lookup; - } -} -EOVCL -} - 1;