]> err.no Git - varnish/commitdiff
* Connect to management socket after select-loop is started.
authorknutroy <knutroy@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 21 Aug 2007 11:48:57 +0000 (11:48 +0000)
committerknutroy <knutroy@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 21 Aug 2007 11:48:57 +0000 (11:48 +0000)
* 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

varnish-tools/regress/lib/Varnish/Test/Engine.pm
varnish-tools/regress/lib/Varnish/Test/Varnish.pm

index 8d0f04898970b953e2035f60c67eb2f514945a34..32824389551a1f3c79902f075ea29cbfbb1d8773 100644 (file)
@@ -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;
 }
 
index 19f7bc25687bf44391eee07188c5f09f34d01601..d6d9c11a84f7767a7db7a46621871f27d4dc18da 100644 (file)
@@ -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);