From: knutroy Date: Tue, 21 Aug 2007 11:48:57 +0000 (+0000) Subject: * Connect to management socket after select-loop is started. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20d009571d6601ad6a95b62332fc3aaed0cc046d;p=varnish * Connect to management socket after select-loop is started. * Removed Varnish::Test::Varnish::kill() which we do not use. (Varnish::Test::Varnish::shutdown() does kill() and more.) git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1914 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-tools/regress/lib/Varnish/Test/Engine.pm b/varnish-tools/regress/lib/Varnish/Test/Engine.pm index 8d0f0489..32824389 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Engine.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Engine.pm @@ -73,6 +73,13 @@ sub new($$;%) { $self->{'server'} = Varnish::Test::Server->new($self); $self->{'varnish'} = Varnish::Test::Varnish->new($self); + my ($ev) = $self->run_loop('ev_varnish_started', 'ev_varnish_timeout'); + + if ($ev eq 'ev_varnish_timeout') { + $self->{'varnish'}->shutdown; + die "Varnish did not start\n"; + } + return $self; } diff --git a/varnish-tools/regress/lib/Varnish/Test/Varnish.pm b/varnish-tools/regress/lib/Varnish/Test/Varnish.pm index 19f7bc25..d6d9c11a 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Varnish.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Varnish.pm @@ -136,21 +136,11 @@ sub new($$;$) { $self->{'mux'}->add($self->{'stderr'}); $self->{'mux'}->set_callback_object($self, $self->{'stderr'}); - # Wait up to 5 seconds for Varnish to accept our connection - # on the management port - for (my $i = 0; $i < 10; ++$i) { - last if $self->{'socket'} = IO::Socket::INET-> - new(Type => SOCK_STREAM, - PeerAddr => $engine->{'config'}->{'telnet_address'}); - select(undef, undef, undef, 0.5); - } - if (!defined($self->{'socket'})) { - kill(15, delete $self->{'pid'}); - die "Varnish did not start\n"; - } - $self->{'mux'}->add($self->{'socket'}); - $self->{'mux'}->set_callback_object($self, $self->{'socket'}); - $self->{'state'} = 'stopped'; + # If we don't hear "rolling(2)..." from Varnish's STDERR within 5 + # seconds, something must be wrong. + $self->{'mux'}->set_timeout($self->{'stderr'}, 5); + + $self->{'state'} = 'init'; return $self; } @@ -277,23 +267,26 @@ sub shutdown($) { if $self->{'pid'}; } -sub kill($;$) { - my ($self, $signal) = @_; - - $signal ||= 15; - die "Not running\n" - unless defined($self->{'pid'}); - kill($signal, $self->{'pid'}); - delete $self->{'pid'}; -} - sub mux_input($$$$) { my ($self, $mux, $fh, $data) = @_; $self->log($$data); - $self->{'mux'}->set_timeout($fh, undef); - if ($fh == $self->{'socket'}) { + if ($fh == $self->{'stderr'} and $$data =~ s/^rolling\(2\)\.\.\.//m) { + # Varnish appears to have been started correctly, so connect + # to management socket. + $self->{'mux'}->set_timeout($fh, undef); + $self->{'state'} = 'stopped'; + $self->{'socket'} = IO::Socket::INET + ->new('Type' => SOCK_STREAM, + 'PeerAddr' => $self->{'engine'}->{'config'}->{'telnet_address'}); + die "Unable to connect to management socket\n" + unless defined($self->{'socket'}); + $self->{'mux'}->add($self->{'socket'}); + $self->{'mux'}->set_callback_object($self, $self->{'socket'}); + $self->{'engine'}->ev_varnish_started; + } elsif (exists($self->{'socket'}) and $fh == $self->{'socket'}) { + $self->{'mux'}->set_timeout($fh, undef); die "syntax error\n" unless ($$data =~ m/^([1-5][0-9][0-9]) (\d+) *$/m); my ($line, $code, $len) = ($&, $1, $2);