changeset 945:d73bef563aea

Tests: speed up HTTP/2 tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 15 Jun 2016 13:27:56 +0300
parents 235f796c2861
children e3df9c2100de
files h2.t h2_cache.t h2_fastcgi_request_buffering.t h2_headers.t h2_limit_conn.t h2_proxy_request_buffering.t h2_proxy_request_buffering_ssl.t h2_request_body.t lib/Test/Nginx/HTTP2.pm
diffstat 9 files changed, 41 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/h2.t
+++ b/h2.t
@@ -226,6 +226,9 @@ is($frame->{sid}, 0, 'PING stream');
 
 # timeouts
 
+SKIP: {
+skip 'long tests', 6 unless $ENV{TEST_NGINX_UNSAFE};
+
 push my @sess, new_session(8089, pure => 1);
 push @sess, new_session(8089, pure => 1);
 h2_ping($sess[-1], 'SEE-THIS');
@@ -253,6 +256,8 @@ is($frame, undef, 'idle timeout - new co
 ok($frame, 'idle timeout - idle connection GOAWAY');
 is($frame->{code}, 0, 'idle timeout - idle connection code');
 
+}
+
 # GOAWAY
 
 h2_goaway(new_session(), 0, 0, 5);
@@ -280,7 +285,7 @@ local $TODO = 'not yet';
 
 $sess = new_session();
 h2_goaway($sess, 1, 0, 5, 'foobar');
-$frames = h2_read($sess, all => [{ type => "GOAWAY" }]);
+$frames = h2_read($sess, all => [{ type => "GOAWAY" }], wait => 0.5);
 
 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
 ok($frame, 'GOAWAY invalid stream - GOAWAY frame');
@@ -706,7 +711,7 @@ h2_ping($sess, 'SEE-THIS');
 ok($frame, 'iws - PING not blocked');
 
 h2_window($sess, 2**16, $sid);
-$frames = h2_read($sess);
+$frames = h2_read($sess, wait => 0.2);
 is(@$frames, 0, 'iws - updated stream window');
 
 h2_window($sess, 2**16);
@@ -765,7 +770,7 @@ is($frame, undef, 'negative window - no 
 
 h2_window($sess, 2**16 - 1 - 42 - 1024, $sid);
 
-$frames = h2_read($sess);
+$frames = h2_read($sess, wait => 0.2);
 is(@$frames, 0, 'zero window - no data');
 
 h2_window($sess, 1, $sid);
@@ -847,7 +852,7 @@ h2_window($sess, 2**30);
 select undef, undef, undef, 0.4;
 
 h2_rst($sess, $sid, 8);
-h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
+h2_read($sess, all => [{ sid => $sid, fin => 1 }], wait => 0.2);
 
 $sid = new_stream($sess);
 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
--- a/h2_cache.t
+++ b/h2_cache.t
@@ -114,8 +114,8 @@ ok($frame, 'proxy cache - request body -
 $sess = new_session();
 $sid = new_stream($sess, { path => '/cache/t.html?1', method => 'HEAD' });
 
-$frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
-push @$frames, $_ for @{h2_read($sess, all => [{ sid => $sid }])};
+$frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }], wait => 0.2);
+push @$frames, $_ for @{h2_read($sess, all => [{ sid => $sid }], wait => 0.2)};
 ok(!grep ({ $_->{type} eq "DATA" } @$frames), 'proxy cache HEAD - no body');
 
 # proxy cache - expect no stray empty DATA frame
@@ -141,7 +141,7 @@ is(join(' ', map { $_->{flags} } @data),
 	{ path => '/proxy_buffering_off/t.html?1', method => 'HEAD' });
 
 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
-push @$frames, $_ for @{h2_read($sess, all => [{ sid => $sid }])};
+push @$frames, $_ for @{h2_read($sess, all => [{ sid => $sid }], wait => 0.2)};
 ok(!grep ({ $_->{type} eq "DATA" } @$frames),
 	'proxy cache HEAD buffering off - no body');
 
--- a/h2_fastcgi_request_buffering.t
+++ b/h2_fastcgi_request_buffering.t
@@ -87,7 +87,7 @@ is($f->{http_end}(), 200, 'many - respon
 
 $f = get_body('/');
 ok($f->{headers}, 'empty');
-is($f->{upload}('', body_more => 1), '', 'empty - part');
+is($f->{upload}('', body_more => 1, wait => 0.2), '', 'empty - part');
 is($f->{upload}(''), '_eos', 'empty - part 2');
 is($f->{http_end}(), 200, 'empty - response');
 
@@ -137,7 +137,7 @@ is($f->{http_end}(), 200, 'cl many - res
 
 $f = get_body('/', 'content-length' => 0);
 ok($f->{headers}, 'cl empty');
-is($f->{upload}('', body_more => 1), '', 'cl empty - part');
+is($f->{upload}('', body_more => 1, wait => 0.2), '', 'cl empty - part');
 is($f->{upload}(''), '_eos', 'cl empty - part 2');
 is($f->{http_end}(), 200, 'cl empty - response');
 
@@ -222,13 +222,14 @@ sub get_body {
 	$f->{upload} = sub {
 		my ($body, %extra) = @_;
 		my $len = length($body);
+		my $wait = $extra{wait};
 
 		h2_body($sess, $body, { %extra });
 
 		$body = '';
 
 		for (1 .. 10) {
-			my $buf = raw_read($client, '', 1, \&log2i)
+			my $buf = raw_read($client, '', 1, \&log2i, $wait)
 				or return '';
 
 			while (my $h = fastcgi_read_record(\$buf)) {
--- a/h2_headers.t
+++ b/h2_headers.t
@@ -962,7 +962,7 @@ local $TODO = 'not yet' unless $t->has_v
 	{ name => ':authority', value => 'localhost', mode => 1 },
 	{ name => 'x_foo', value => "x-bar", mode => 2 },
 	{ name => 'referer', value => "see-this", mode => 1 }]});
-$frames = h2_read($sess, all => [{ type => 'RST_STREAM' }]);
+$frames = h2_read($sess, all => [{ type => 'HEADERS' }]);
 
 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
 is($frame->{headers}->{'x-referer'}, 'see-this', 'after invalid header name');
--- a/h2_limit_conn.t
+++ b/h2_limit_conn.t
@@ -65,7 +65,7 @@ my ($frame) = grep { $_->{type} eq "HEAD
 is($frame->{headers}->{':status'}, 200, 'limit_conn first stream');
 
 my $sid2 = new_stream($sess, { path => '/t.html' });
-$frames = h2_read($sess, all => [{ sid => $sid2, fin => 0 }]);
+$frames = h2_read($sess, all => [{ sid => $sid2, length => 1 }]);
 
 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid2 } @$frames;
 is($frame->{headers}->{':status'}, 503, 'limit_conn rejected');
@@ -90,7 +90,7 @@ h2_rst($sess, $sid, 5);
 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 1');
 
 $sid2 = new_stream($sess, { path => '/t.html' });
-$frames = h2_read($sess, all => [{ sid => $sid2, fin => 0 }]);
+$frames = h2_read($sess, all => [{ sid => $sid2, length => 1 }]);
 
 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid2 } @$frames;
 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 2');
--- a/h2_proxy_request_buffering.t
+++ b/h2_proxy_request_buffering.t
@@ -99,8 +99,8 @@ is($f->{http_end}(), 200, 'many - respon
 
 $f = get_body('/', 'content-length' => 0);
 ok($f->{headers}, 'empty');
-is($f->{upload}('', body_more => 1), '', 'empty - part');
-is($f->{upload}(''), '', 'empty - part 2');
+is($f->{upload}('', body_more => 1, wait => 0.2), '', 'empty - part');
+is($f->{upload}('', wait => 0.2), '', 'empty - part 2');
 is($f->{http_end}(), 200, 'empty - response');
 
 $f = get_body('/', 'content-length' => 1536);
@@ -149,7 +149,7 @@ is($f->{http_end}(), 200, 'chunked many 
 
 $f = get_body('/chunked');
 ok($f->{headers}, 'chunked empty');
-is($f->{upload}('', body_more => 1), '', 'chunked empty - part');
+is($f->{upload}('', body_more => 1, wait => 0.2), '', 'chunked empty - part');
 is($f->{upload}(''), '0' . CRLF . CRLF, 'chunked empty - part 2');
 is($f->{http_end}(), 200, 'chunked empty - response');
 
@@ -197,11 +197,11 @@ sub get_body {
 	my $chunked = $f->{headers} =~ /chunked/;
 
 	my $body_read = sub {
-		my ($s, $buf, $len) = @_;
+		my ($s, $buf, $len, $wait) = @_;
 
 		for (1 .. 10) {
-			$buf = raw_read($s, $buf, length($buf) + 1, \&log2i)
-				or return '';
+			$buf = raw_read($s, $buf, length($buf) + 1, \&log2i,
+				$wait) or return '';
 
 			my $got = 0;
 			$got += $chunked ? hex $_ : $_ for $chunked
@@ -218,7 +218,7 @@ sub get_body {
 
 		h2_body($sess, $body, { %extra });
 
-		return $body_read->($client, '', length($body));
+		return $body_read->($client, '', length($body), $extra{wait});
 	};
 	$f->{http_end} = sub {
 		$client->write(<<EOF);
--- a/h2_proxy_request_buffering_ssl.t
+++ b/h2_proxy_request_buffering_ssl.t
@@ -133,8 +133,8 @@ is($f->{http_end}(), 200, 'many - respon
 
 $f = get_body('/', 'content-length' => 0);
 ok($f->{headers}, 'empty');
-is($f->{upload}('', body_more => 1), '', 'empty - part');
-is($f->{upload}(''), '', 'empty - part 2');
+is($f->{upload}('', body_more => 1, wait => 0.2), '', 'empty - part');
+is($f->{upload}('', wait => 0.2), '', 'empty - part 2');
 is($f->{http_end}(), 200, 'empty - response');
 
 $f = get_body('/', 'content-length' => 10);
@@ -174,7 +174,7 @@ is($f->{http_end}(), 200, 'chunked many 
 
 $f = get_body('/chunked');
 ok($f->{headers}, 'chunked empty');
-is($f->{upload}('', body_more => 1), '', 'chunked empty - part');
+is($f->{upload}('', body_more => 1, wait => 0.2), '', 'chunked empty - part');
 is($f->{upload}(''), '0' . CRLF . CRLF, 'chunked empty - part 2');
 is($f->{http_end}(), 200, 'chunked empty - response');
 
@@ -222,11 +222,11 @@ sub get_body {
 	my $chunked = $f->{headers} =~ /chunked/;
 
 	my $body_read = sub {
-		my ($s, $buf, $len) = @_;
+		my ($s, $buf, $len, $wait) = @_;
 
 		for (1 .. 10) {
-			$buf = raw_read($s, $buf, length($buf) + 1, \&log2i)
-				or return '';
+			$buf = raw_read($s, $buf, length($buf) + 1, \&log2i,
+				$wait) or return '';
 
 			my $got = 0;
 			$got += $chunked ? hex $_ : $_ for $chunked
@@ -243,7 +243,7 @@ sub get_body {
 
 		h2_body($sess, $body, { %extra });
 
-		return $body_read->($client, '', length($body));
+		return $body_read->($client, '', length($body), $extra{wait});
 	};
 	$f->{http_end} = sub {
 		$client->write(<<EOF);
--- a/h2_request_body.t
+++ b/h2_request_body.t
@@ -155,7 +155,7 @@ local $TODO = 'not yet';
 
 $sess = new_session();
 $sid = new_stream($sess, { body_more => 1 });
-$frames = h2_read($sess, all => [{ type => 'RST_STREAM' }]);
+$frames = h2_read($sess, all => [{ type => 'RST_STREAM' }], wait => 0.5);
 
 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames;
 is($frame->{code}, 0, 'request body discarded - zero RST_STREAM');
--- a/lib/Test/Nginx/HTTP2.pm
+++ b/lib/Test/Nginx/HTTP2.pm
@@ -60,7 +60,7 @@ sub h2_goaway {
 
 	my @bufs = map {
 		raw_write($sess->{socket}, substr $buf, 0, $_, "");
-		select undef, undef, undef, 0.4;
+		select undef, undef, undef, 0.2;
 	} @{$extra{split}};
 
 	raw_write($sess->{socket}, $buf);
@@ -265,11 +265,12 @@ sub h2_read {
 	my (@got);
 	my $s = $sess->{socket};
 	my $buf = '';
+	my $wait = $extra{wait};
 
 	local $Data::Dumper::Terse = 1;
 
 	while (1) {
-		$buf = raw_read($s, $buf, 9);
+		$buf = raw_read($s, $buf, 9, \&log_in, $wait);
 		last if length $buf < 9;
 
 		my $length = unpack_length($buf);
@@ -280,7 +281,7 @@ sub h2_read {
 		substr($stream, 0, 1) = 0;
 		$stream = unpack("N", pack("B32", $stream));
 
-		$buf = raw_read($s, $buf, $length + 9);
+		$buf = raw_read($s, $buf, $length + 9, \&log_in, $wait);
 		last if length($buf) < $length + 9;
 
 		$buf = substr($buf, 9);
@@ -410,11 +411,12 @@ sub unpack_length {
 }
 
 sub raw_read {
-	my ($s, $buf, $len, $log) = @_;
+	my ($s, $buf, $len, $log, $timo) = @_;
 	$log = \&log_in unless defined $log;
+	$timo = 3 unless $timo;
 	my $got = '';
 
-	while (length($buf) < $len && IO::Select->new($s)->can_read(1))  {
+	while (length($buf) < $len && IO::Select->new($s)->can_read($timo)) {
 		$s->sysread($got, 16384) or last;
 		$log->($got);
 		$buf .= $got;