From: des Date: Mon, 20 Aug 2007 07:56:25 +0000 (+0000) Subject: Change the way the result from a command is reported. Instead of separate X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1a275282287cc20e52fbb223f43071e35611789;p=varnish 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. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1864 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-tools/regress/lib/Varnish/Test/Case.pm b/varnish-tools/regress/lib/Varnish/Test/Case.pm index fbded823..8361977f 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case.pm @@ -72,6 +72,7 @@ sub log($$) { sub init($) { my ($self) = @_; + my ($code, $text); $self->{'engine'}->{'case'} = $self; @@ -82,21 +83,26 @@ sub init($) { 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"; + } + ($code, $text) = $varnish->use_vcl(ref($self)); + if ($code != 200) { + $self->{'failed'} += 1; + die "Unable to load VCL\n"; } - $varnish->use_vcl(ref($self)); - $self->run_loop('ev_varnish_command_ok'); } $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 @@ sub fini($) { # 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'}; diff --git a/varnish-tools/regress/lib/Varnish/Test/Varnish.pm b/varnish-tools/regress/lib/Varnish/Test/Varnish.pm index 71792f70..c5b5921f 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Varnish.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Varnish.pm @@ -183,21 +183,27 @@ sub send_command($@) { } } 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 @@ sub start_child($) { 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 @@ sub stop_child($) { 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 @@ sub mux_input($$$$) { 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';