r1864 - trunk/varnish-tools/regress/lib/Varnish/Test

des at projects.linpro.no des at projects.linpro.no
Mon Aug 20 09:56:25 CEST 2007


Author: des
Date: 2007-08-20 09:56:25 +0200 (Mon, 20 Aug 2007)
New Revision: 1864

Modified:
   trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm
   trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm
Log:
Change the way the result from a command is reported.  Instead of separate
ev_varnish_command_ok and ev_varnish_command_unknown events, we now emit
a single ev_varnish_result event accompanied by the result code and text.
Furthermore, Varnish::Test::Varnish::send_command() will now wait for this
event and return the code and text.

Note that this reintroduces a race between ev_varnish_child_stopped and
ev_varnish_result; this will be dealt with in a later commit.


Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm	2007-08-20 07:51:03 UTC (rev 1863)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm	2007-08-20 07:56:25 UTC (rev 1864)
@@ -72,6 +72,7 @@
 
 sub init($) {
     my ($self) = @_;
+    my ($code, $text);
 
     $self->{'engine'}->{'case'} = $self;
 
@@ -82,21 +83,26 @@
     if (${ref($self)."::VCL"}) {
 	my $vcl = $varnish->backend_block('main') . ${ref($self)."::VCL"};
 
-	$varnish->send_vcl(ref($self), $vcl);
-	my ($ev, $resp) = $self->run_loop('ev_varnish_command_ok', 'ev_varnish_command_unknown');
-	if ($ev eq 'ev_varnish_command_unknown') {
+	($code, $text) = $varnish->send_vcl(ref($self), $vcl);
+	if ($code != 200) {
 	    $self->{'failed'} += 1;
-	    die "Unable to load VCL.\n"
+	    die "Unable to load VCL\n";
 	}
-	$varnish->use_vcl(ref($self));
-	$self->run_loop('ev_varnish_command_ok');
+	($code, $text) = $varnish->use_vcl(ref($self));
+	if ($code != 200) {
+	    $self->{'failed'} += 1;
+	    die "Unable to load VCL\n";
+	}
     }
 
     $varnish->set_param('vcl_trace' => 'on');
-    $self->run_loop('ev_varnish_command_ok');
 
     # Start the child
-    $varnish->start_child();
+    ($code, $text) = $varnish->start_child();
+    if ($code != 200) {
+	$self->{'failed'} += 1;
+	die "Unable to start child\n";
+    }
     $self->run_loop('ev_varnish_child_started');
 }
 
@@ -107,16 +113,13 @@
 
     # Stop the worker process
     $varnish->stop_child();
-    # Wait for both events, the order is unpredictable, so wait for
-    # any of them both times.
-    $self->run_loop('ev_varnish_child_stopped', 'ev_varnish_command_ok');
-    $self->run_loop('ev_varnish_child_stopped', 'ev_varnish_command_ok');
+    $self->run_loop('ev_varnish_child_stopped');
 
     # Revert to initial VCL script
     no strict 'refs';
     if (${ref($self)."::VCL"}) {
 	$varnish->use_vcl('boot');
-	$self->run_loop('ev_varnish_command_ok', 'ev_varnish_command_unknown');
+	$self->run_loop('ev_varnish_result');
     }
 
     delete $self->{'engine'}->{'case'};

Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm
===================================================================
--- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm	2007-08-20 07:51:03 UTC (rev 1863)
+++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm	2007-08-20 07:56:25 UTC (rev 1864)
@@ -183,21 +183,27 @@
 	}
     }
     my $command = join(' ', @args);
+    $self->log("sending command: $command");
     $self->{'mux'}->write($self->{'socket'}, $command . "\n");
     $self->{'mux'}->set_timeout($self->{'socket'}, 2);
     $self->{'pending'} = $command;
+    my ($ev, $code, $text) =
+	$self->{'engine'}->run_loop('ev_varnish_result',
+				    'ev_varnish_timeout');
+    delete $self->{'pending'};
+    return ($code, $text);
 }
 
 sub send_vcl($$$) {
     my ($self, $config, $vcl) = @_;
 
-    $self->send_command('vcl.inline', $config, $vcl);
+    return $self->send_command('vcl.inline', $config, $vcl);
 }
 
 sub use_vcl($$) {
     my ($self, $config) = @_;
 
-    $self->send_command('vcl.use', $config);
+    return $self->send_command('vcl.use', $config);
 }
 
 sub start_child($) {
@@ -207,7 +213,7 @@
     die "already started\n"
 	if $self->{'state'} eq "started";
 
-    $self->send_command("start");
+    return $self->send_command("start");
 }
 
 sub stop_child($) {
@@ -217,13 +223,13 @@
     die "already stopped\n"
 	if $self->{'state'} eq 'stopped';
 
-    $self->send_command("stop");
+    return $self->send_command("stop");
 }
 
 sub set_param($$$) {
     my ($self, $param, $value) = @_;
 
-    $self->send_command('param.set', $param, $value);
+    return $self->send_command('param.set', $param, $value);
 }
 
 sub shutdown($) {
@@ -270,11 +276,7 @@
 	my $text = substr($$data, length($line), $len);
 	substr($$data, 0, length($line) + $len + 1, '');
 
-	$self->{'engine'}->ev_varnish_command_ok(delete $self->{'pending'})
-	    if ($code eq 200 and $self->{'pending'});
-
-	$self->{'engine'}->ev_varnish_command_unknown(delete $self->{'pending'})
-	    if ($code eq 300 and $self->{'pending'});
+	$self->{'engine'}->ev_varnish_result($code, $text);
     } else {
 	if ($$data =~ /^rolling\(2\)\.\.\./m) {
 	    $self->{'state'} = 'stopped';




More information about the varnish-commit mailing list