diff h2_fastcgi_request_buffering.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_fastcgi_request_buffering.t
+++ b/h2_fastcgi_request_buffering.t
@@ -16,7 +16,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;
 
 ###############################################################################
 
@@ -197,9 +197,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, },
@@ -207,13 +207,13 @@ 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 $h = fastcgi_read_record(\$f->{headers});
 	my $version = $h->{version};
@@ -224,13 +224,12 @@ sub get_body {
 		my $len = length($body);
 		my $wait = $extra{wait};
 
-		h2_body($sess, $body, { %extra });
+		$s->h2_body($body, { %extra });
 
 		$body = '';
 
 		for (1 .. 10) {
-			my $buf = raw_read($client, '', 1, \&log2i, $wait)
-				or return '';
+			my $buf = backend_read($client, $wait) or return '';
 
 			while (my $h = fastcgi_read_record(\$buf)) {
 
@@ -260,13 +259,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('||', @_); }