]> err.no Git - varnish/commitdiff
Remove the "magic" StartChild, StopChild and LoadVCL test cases. Instead,
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 13 Jun 2007 11:26:09 +0000 (11:26 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 13 Jun 2007 11:26:09 +0000 (11:26 +0000)
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

varnish-tools/regress/lib/Varnish/Test.pm
varnish-tools/regress/lib/Varnish/Test/Case.pm
varnish-tools/regress/lib/Varnish/Test/Case/LoadVCL.pm [deleted file]
varnish-tools/regress/lib/Varnish/Test/Case/StartChild.pm [deleted file]
varnish-tools/regress/lib/Varnish/Test/Case/StopChild.pm [deleted file]
varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm
varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm

index 3fb590f231a7ac2a1b6d72d1cf3c44605266a739..a631c13f20c883d161ac86820854adc6df3b5e32 100644 (file)
@@ -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;
 }
index c4d188e78a93954769f6bd447b5bc3fc7a8b2995..93332b298c067adeb2754188cdff9a7f87140b1e 100644 (file)
@@ -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 (file)
index 0ddcd6e..0000000
+++ /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 (file)
index 66896d8..0000000
+++ /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 (file)
index 32efca8..0000000
+++ /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;
index b3360dadb8556153f39a59af2e39084ed385d387..c68632efc9ae4cccce2f688166c3a7de9dbc6f3c 100644 (file)
@@ -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;
index 0d738e4f6d6fd6c566b8621b4825e499bdc657fc..bb9921f218bc1b390550c12fefcf7eae9bdaf67a 100644 (file)
@@ -35,6 +35,15 @@ use base 'Varnish::Test::Case';
 
 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 @@ sub ev_server_request($$$$) {
     $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;