diff http_resolver.t @ 438:60888e2c3f5a

Tests: new http_start() and http_end() functions. When used together, they allow to break an http request into two separate send/receive phases and are used to run long requests asynchronously. An http() "start" extra flag introduced as a convenience shortcut.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 18 Jul 2014 13:19:55 +0400
parents 4984dac109db
children 0bc79a098213
line wrap: on
line diff
--- a/http_resolver.t
+++ b/http_resolver.t
@@ -15,7 +15,7 @@ use Test::More;
 BEGIN { use FindBin; chdir($FindBin::Bin); }
 
 use lib 'lib';
-use Test::Nginx;
+use Test::Nginx qw/ :DEFAULT http_end /;
 
 ###############################################################################
 
@@ -94,7 +94,7 @@ EOF
 
 # schedule resend test, which takes abound 5 seconds to complete
 
-my $s = http_start('id.example.net', '/resend');
+my $s = http_host_header('id.example.net', '/resend', start => 1);
 
 like(http_host_header('a.example.net', '/'), qr/200 OK/, 'A');
 
@@ -231,8 +231,8 @@ like(http_end($s), qr/200 OK/, 'resend a
 ###############################################################################
 
 sub http_host_header {
-	my ($host, $uri) = @_;
-	return http(<<EOF);
+	my ($host, $uri, %extra) = @_;
+	return http(<<EOF, %extra);
 GET $uri HTTP/1.0
 Host: $host
 
@@ -248,57 +248,6 @@ X-Name: $host
 EOF
 }
 
-sub http_start {
-	my ($host, $uri) = @_;
-
-	my $s;
-	my $request = <<EOF;
-GET $uri HTTP/1.0
-Host: $host
-
-EOF
-
-	eval {
-		local $SIG{ALRM} = sub { die "timeout\n" };
-		local $SIG{PIPE} = sub { die "sigpipe\n" };
-		alarm(5);
-		$s = IO::Socket::INET->new(
-			Proto => 'tcp',
-			PeerAddr => '127.0.0.1:8080'
-		);
-		log_out($request);
-		$s->print($request);
-		alarm(0);
-	};
-	alarm(0);
-	if ($@) {
-		log_in("died: $@");
-		return undef;
-	}
-	return $s;
-}
-
-sub http_end {
-	my ($s) = @_;
-	my $reply;
-
-	eval {
-		local $SIG{ALRM} = sub { die "timeout\n" };
-		local $SIG{PIPE} = sub { die "sigpipe\n" };
-		alarm(3);
-		local $/;
-		$reply = $s->getline();
-		log_in($reply);
-		alarm(0);
-	};
-	alarm(0);
-	if ($@) {
-		log_in("died: $@");
-		return undef;
-	}
-	return $reply;
-}
-
 ###############################################################################
 
 sub reply_handler {