From: knutroy Date: Thu, 16 Aug 2007 13:07:55 +0000 (+0000) Subject: * Added automatic shutdown of Client-objects used by a test. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75211725fe107172c5375137edd64aee9cfa6ca0;p=varnish * Added automatic shutdown of Client-objects used by a test. * Added more diagnostic messages wrt. left-over input data/junk. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1850 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 a39bbf34..cd353dc3 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case.pm @@ -149,6 +149,11 @@ sub run($;@) { $self->log(sprintf("%d: FAIL: %s: %s", $self->{'count'}, $method, $@)); } + # Make sure all clients have closed their connections. + foreach my $client (@{$self->{'engine'}->{'clients'}}) { + $client->shutdown; + } + @{$self->{'engine'}->{'clients'}} = (); } $self->{'stop'} = [gettimeofday()]; } diff --git a/varnish-tools/regress/lib/Varnish/Test/Client.pm b/varnish-tools/regress/lib/Varnish/Test/Client.pm index 88d90238..99f71ead 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Client.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Client.pm @@ -45,28 +45,33 @@ use strict; use IO::Socket::INET; +our $id_seq = 1; + sub new($$) { my ($this, $engine, $attrs) = @_; my $class = ref($this) || $this; my $self = bless({ 'engine' => $engine, 'mux' => $engine->{'mux'}, + 'id' => $id_seq++, 'requests' => 0, 'responses' => 0 }, $class); + push(@{$self->{'engine'}->{'clients'}}, $self); + return $self; } sub log($$;$) { my ($self, $str, $extra_prefix) = @_; - $self->{'engine'}->log($self, 'CLI: ' . ($extra_prefix || ''), $str); + $self->{'engine'}->log($self, sprintf('CLI[%d]: ', $self->{'id'}) . ($extra_prefix || ''), $str); } sub logf($$;@) { my ($self, $fmt, @args) = @_; - $self->{'engine'}->log($self, 'CLI: ', sprintf($fmt, @args)); + $self->{'engine'}->log($self, sprintf('CLI[%d]: ', $self->{'id'}), sprintf($fmt, @args)); } sub send_request($$;$) { @@ -97,10 +102,21 @@ sub got_response($$) { } sub shutdown($) { - my ($self, $how) = @_; + my ($self) = @_; - $self->{'mux'}->close($self->{'fh'}); - $self->{'fh'} = undef; + if (defined($self->{'fh'})) { + my $inbuffer = $self->{'mux'}->inbuffer($self->{'fh'}); + + if ($inbuffer ne '') { + use Data::Dumper; + + $self->log('Discarding: ' . Dumper(\$inbuffer)); + $self->{'mux'}->inbuffer($self->{'fh'}, ''); + } + + $self->{'mux'}->close($self->{'fh'}); + $self->{'fh'} = undef; + } } sub mux_input($$$$) { @@ -204,7 +220,7 @@ sub mux_timeout($$$) { sub mux_close($$) { my ($self, $mux, $fh) = @_; - delete $self->{'fh'}; + $self->{'fh'} = undef; } 1; diff --git a/varnish-tools/regress/lib/Varnish/Test/Engine.pm b/varnish-tools/regress/lib/Varnish/Test/Engine.pm index cf453a20..fd327db4 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Engine.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Engine.pm @@ -66,6 +66,7 @@ sub new($$;%) { my $self = bless({ 'mux' => IO::Multiplex->new, 'controller' => $controller, 'config' => \%config, + 'clients' => [], 'pending' => [] }, $class); $self->{'server'} = Varnish::Test::Server->new($self); diff --git a/varnish-tools/regress/lib/Varnish/Test/Server.pm b/varnish-tools/regress/lib/Varnish/Test/Server.pm index 337041db..d3c287ab 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Server.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Server.pm @@ -145,6 +145,15 @@ sub send_response($$) { sub shutdown($) { my ($self) = @_; + my $inbuffer = $self->{'mux'}->inbuffer($self->{'fh'}); + + if ($inbuffer ne '') { + use Data::Dumper; + + $self->{'server'}->log('Junk or incomplete request. Discarding: ' . Dumper(\$inbuffer)); + $self->{'mux'}->inbuffer($self->{'fh'}, ''); + } + $self->{'mux'}->close($self->{'fh'}); } @@ -224,8 +233,12 @@ sub mux_eof($$$$) { # of request, so if there is anything left in input buffer, it # must be incomplete because "mux_input" left it there. - die "Junk or incomplete request\n" - unless $$data eq ''; + if ($$data ne '') { + use Data::Dumper; + + $self->{'server'}->log('Junk or incomplete request. Discarding: ' . Dumper($data)); + $$data = ''; + } } 1;