Mailing List Archive

r1512 - in trunk/varnish-tools/regress/lib/Varnish: . Test Test/Case
Author: des
Date: 2007-06-13 13:26:09 +0200 (Wed, 13 Jun 2007)
New Revision: 1512

Removed:
trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm
trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm
trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm
Modified:
trunk/varnish-tools/regress/lib/Varnish/Test.pm
trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm
trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm
trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm
Log:
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().


Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm 2007-06-13 11:12:07 UTC (rev 1511)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm 2007-06-13 11:26:09 UTC (rev 1512)
@@ -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;

Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm 2007-06-13 11:12:07 UTC (rev 1511)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm 2007-06-13 11:26:09 UTC (rev 1512)
@@ -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;

Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm 2007-06-13 11:12:07 UTC (rev 1511)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm 2007-06-13 11:26:09 UTC (rev 1512)
@@ -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;

Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-13 11:12:07 UTC (rev 1511)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-06-13 11:26:09 UTC (rev 1512)
@@ -35,6 +35,12 @@

use Carp 'croak';

+our $VCL = "
+sub vcl_recv {
+ pass;
+}
+";
+
sub testVersionMatch($) {
my ($self) = @_;

@@ -85,14 +91,4 @@
$connection->shutdown;
}

-sub vcl($) {
- my ($self) = @_;
-
- return $self->{'engine'}->{'varnish'}->backend_block('main') . <<'EOVCL'
-sub vcl_recv {
- pass;
-}
-EOVCL
-}
-
1;

Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-13 11:12:07 UTC (rev 1511)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-06-13 11:26:09 UTC (rev 1512)
@@ -35,6 +35,15 @@

use Carp 'croak';

+our $VCL = <<EOVCL;
+sub vcl_recv {
+ if (req.request == "POST" &&
+ (!req.http.content-length || req.http.content-length == "0")) {
+ lookup;
+ }
+}
+EOVCL
+
our $body = "Hello World!\n";

sub testBodyInCachedPOST($) {
@@ -63,17 +72,4 @@
$connection->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;

Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-13 11:12:07 UTC (rev 1511)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-06-13 11:26:09 UTC (rev 1512)
@@ -54,16 +54,59 @@
$self->{'engine'}->log($self, 'CAS: ', $str);
}

+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->{'engine'}->{'case'} = $self;
-
$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 @@
$self->{'count'}, $method, $@));
}
}
-
- delete $self->{'engine'}->{'case'};
}

sub run_loop($) {
@@ -99,6 +140,12 @@
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) = @_;


Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-13 11:12:07 UTC (rev 1511)
+++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-06-13 11:26:09 UTC (rev 1512)
@@ -70,9 +70,6 @@
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 @@
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,15 +106,10 @@

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;
+ $case->fini;

- Varnish::Test::Case::StopChild->new($self->{'engine'})->run;
-
$self->stop_engine;
}