diff h2_proxy_request_buffering_ssl.t @ 948:4dc302d8e04f

Tests: changed HTTP2 package to act as a class. Stopped exporting any subroutines. A subset of them now act as class methods.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 17 Jun 2016 11:36:33 +0300
parents d73bef563aea
children e9064d691790
line wrap: on
line diff
--- a/h2_proxy_request_buffering_ssl.t
+++ b/h2_proxy_request_buffering_ssl.t
@@ -18,7 +18,7 @@ BEGIN { use FindBin; chdir($FindBin::Bin
 
 use lib 'lib';
 use Test::Nginx;
-use Test::Nginx::HTTP2 qw/ :DEFAULT :frame :io /;
+use Test::Nginx::HTTP2;
 
 ###############################################################################
 
@@ -201,9 +201,9 @@ sub get_body {
 	)
 		or die "Can't create listening socket: $!\n";
 
-	my $sess = new_session(8080);
+	my $s = Test::Nginx::HTTP2->new();
 	my $sid = exists $extra{'content-length'}
-		? new_stream($sess, { headers => [
+		? $s->new_stream({ headers => [
 			{ name => ':method', value => 'GET' },
 			{ name => ':scheme', value => 'http' },
 			{ name => ':path', value => $url, },
@@ -211,39 +211,37 @@ sub get_body {
 			{ name => 'content-length',
 				value => $extra{'content-length'} }],
 			body_more => 1 })
-		: new_stream($sess, { path => $url, body_more => 1 });
+		: $s->new_stream({ path => $url, body_more => 1 });
 
 	$client = $server->accept() or return;
 
 	log2c("(new connection $client)");
 
-	$f->{headers} = raw_read($client, '', 1, \&log2i);
+	$f->{headers} = backend_read($client);
 
 	my $chunked = $f->{headers} =~ /chunked/;
 
-	my $body_read = sub {
-		my ($s, $buf, $len, $wait) = @_;
+	$f->{upload} = sub {
+		my ($body, %extra) = @_;
+		my $len = length($body);
+		my $wait = $extra{wait};
+
+		$s->h2_body($body, { %extra });
+
+		$body = '';
 
 		for (1 .. 10) {
-			$buf = raw_read($s, $buf, length($buf) + 1, \&log2i,
-				$wait) or return '';
+			my $buf = backend_read($client, $wait) or return '';
+			$body .= $buf;
 
 			my $got = 0;
 			$got += $chunked ? hex $_ : $_ for $chunked
-				? $buf =~ /(\w+)\x0d\x0a?\w+\x0d\x0a?/g
-				: length($buf);
+				? $body =~ /(\w+)\x0d\x0a?\w+\x0d\x0a?/g
+				: length($body);
 			last if $got >= $len;
 		}
 
-		return $buf;
-	};
-
-	$f->{upload} = sub {
-		my ($body, %extra) = @_;
-
-		h2_body($sess, $body, { %extra });
-
-		return $body_read->($client, '', length($body), $extra{wait});
+		return $body;
 	};
 	$f->{http_end} = sub {
 		$client->write(<<EOF);
@@ -254,13 +252,24 @@ EOF
 
 		$client->close;
 
-		my $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
+		my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
 		my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
 		return $frame->{headers}->{':status'};
 	};
 	return $f;
 }
 
+sub backend_read {
+	my ($s, $timo) = @_;
+	my $buf = '';
+
+	if (IO::Select->new($s)->can_read($timo || 3)) {
+		$s->sysread($buf, 16384) or return;
+		log2i($buf);
+	}
+	return $buf;
+}
+
 sub log2i { Test::Nginx::log_core('|| <<', @_); }
 sub log2o { Test::Nginx::log_core('|| >>', @_); }
 sub log2c { Test::Nginx::log_core('||', @_); }