diff upstream_least_conn.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 98d9b06b087b
children b86c05516e65
line wrap: on
line diff
--- a/upstream_least_conn.t
+++ b/upstream_least_conn.t
@@ -16,7 +16,7 @@ use Socket qw/ CRLF /;
 BEGIN { use FindBin; chdir($FindBin::Bin); }
 
 use lib 'lib';
-use Test::Nginx;
+use Test::Nginx qw/ :DEFAULT http_end /;
 
 ###############################################################################
 
@@ -88,7 +88,7 @@ sub parallel {
 	my (@sockets, %ports);
 
 	for (1 .. $count) {
-		push(@sockets, http_start($uri));
+		push(@sockets, http_get($uri, start => 1));
 		select undef, undef, undef, 0.1;
 	}
 
@@ -102,53 +102,6 @@ sub parallel {
 	return join ', ', map { $_ . ": " . $ports{$_} } sort keys %ports;
 }
 
-sub http_start {
-	my ($uri) = @_;
-
-	my $s;
-	my $request = "GET $uri HTTP/1.0" . CRLF . CRLF;
-
-	eval {
-		local $SIG{ALRM} = sub { die "timeout\n" };
-		local $SIG{PIPE} = sub { die "sigpipe\n" };
-		alarm(3);
-		$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 http_daemon {