changeset 1235:3fc6817cd84a

Tests: explicit peer port in stream tests now required. Notably, this eliminates extra port acquire for the default port number in cases when it was not actually used.
author Andrey Zelenkov <zelenkov@nginx.com>
date Thu, 26 Oct 2017 16:36:13 +0300
parents 0defcc1c87ab
children 93f749c1d5c5
files lib/Test/Nginx/Stream.pm stream_error_log.t stream_geo.t stream_geo_binary.t stream_geo_ipv6.t stream_geoip.t stream_proxy.t stream_split_clients.t stream_ssl_preread.t stream_ssl_variables.t stream_ssl_verify_client.t stream_udp_upstream_least_conn.t stream_upstream_least_conn.t stream_variables.t
diffstat 14 files changed, 19 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/lib/Test/Nginx/Stream.pm
+++ b/lib/Test/Nginx/Stream.pm
@@ -41,7 +41,6 @@ sub new {
 	$self->{_socket} = IO::Socket::INET->new(
 		Proto => "tcp",
 		PeerAddr => '127.0.0.1',
-		PeerPort => port(8080),
 		@_
 	)
 		or die "Can't connect to nginx: $!\n";
--- a/stream_error_log.t
+++ b/stream_error_log.t
@@ -88,7 +88,7 @@ open STDERR, ">&", \*OLDERR;
 
 ###############################################################################
 
-stream()->io('data');
+stream('127.0.0.1:' . port(8080))->io('data');
 
 # error_log levels
 
--- a/stream_geo.t
+++ b/stream_geo.t
@@ -223,7 +223,7 @@ EOF
 
 ###############################################################################
 
-my %data = stream()->read() =~ /(\w+):(\w+)/g;
+my %data = stream('127.0.0.1:' . port(8080))->read() =~ /(\w+):(\w+)/g;
 is($data{geo}, 'loopback', 'geo');
 is($data{geo_include}, 'loopback', 'geo include');
 is($data{geo_delete}, 'world', 'geo delete');
--- a/stream_geo_binary.t
+++ b/stream_geo_binary.t
@@ -65,7 +65,7 @@ EOF
 
 ###############################################################################
 
-my %data = stream()->read() =~ /(\w+):(\w+)/g;
+my %data = stream('127.0.0.1:' . port(8080))->read() =~ /(\w+):(\w+)/g;
 is($data{geo_base_create}, 'loopback', 'geo binary base create');
 is($data{geo_base_include}, 'loopback', 'geo binary base include');
 
--- a/stream_geo_ipv6.t
+++ b/stream_geo_ipv6.t
@@ -90,7 +90,7 @@ EOF
 
 ###############################################################################
 
-my %data = stream()->read() =~ /(\w+):(\w+)/g;
+my %data = stream('127.0.0.1:' . port(8080))->read() =~ /(\w+):(\w+)/g;
 is($data{geo}, 'loopback', 'geo ipv6');
 is($data{geo_delete}, 'world', 'geo ipv6 delete');
 is($data{geo_var}, 'default', 'geo ipv6 from variable');
--- a/stream_geoip.t
+++ b/stream_geoip.t
@@ -178,7 +178,8 @@ is($data{country_name}, 'United States',
 sub stream_pp {
 	my ($ip) = @_;
 	my $type = ($ip =~ ':' ? 'TCP6' : 'TCP4');
-	return stream()->io("PROXY $type $ip 127.0.0.1 8080 8080${CRLF}");
+	return stream('127.0.0.1:' . port(8080))
+		->io("PROXY $type $ip 127.0.0.1 8080 8080${CRLF}");
 }
 
 sub pack_node {
--- a/stream_proxy.t
+++ b/stream_proxy.t
@@ -50,14 +50,14 @@ EOF
 
 ###############################################################################
 
-my $s = stream();
+my $s = stream('127.0.0.1:' . port(8080));
 
 is($s->io('foo1', length => 4), 'bar1', 'proxy connection');
 is($s->io('foo3', length => 4), 'bar3', 'proxy connection again');
 is($s->io('close'), 'close', 'proxy connection close');
 is($s->io('test'), '', 'proxy connection closed');
 
-$s = stream();
+$s = stream('127.0.0.1:' . port(8080));
 
 sleep 3;
 
--- a/stream_split_clients.t
+++ b/stream_split_clients.t
@@ -65,7 +65,7 @@ sub many {
 	my %dist;
 
 	for (1 .. $count) {
-		if (my $data = stream()->read()) {
+		if (my $data = stream('127.0.0.1:' . port(8080))->read()) {
 			$dist{$data} = 0 unless defined $data;
 			$dist{$data}++;
 		}
--- a/stream_ssl_preread.t
+++ b/stream_ssl_preread.t
@@ -159,7 +159,8 @@ is(get_ssl('bar', 8081), $p2, 'sni 2 aga
 is(get_ssl('', 8081), $p3, 'no sni');
 is(get_ssl('foo', 8082), $p3, 'preread off');
 is(get_ssl('foo', 8083), undef, 'preread buffer full');
-is(stream()->io('x' x 1000), "127.0.0.1:$p3", 'not a handshake');
+is(stream('127.0.0.1:' . port(8080))->io('x' x 1000), "127.0.0.1:$p3",
+	'not a handshake');
 
 # ticket #1317
 
--- a/stream_ssl_variables.t
+++ b/stream_ssl_variables.t
@@ -96,7 +96,7 @@ foreach my $name ('localhost') {
 
 my ($s, $ssl);
 
-is(stream()->read(), ':::', 'no ssl');
+is(stream('127.0.0.1:' . port(8080))->read(), ':::', 'no ssl');
 
 ($s, $ssl) = get_ssl_socket(port(8081));
 like(Net::SSLeay::read($ssl), qr/^\.:(\w{64})?:[\w-]+:(TLS|SSL)v(\d|\.)+$/,
--- a/stream_ssl_verify_client.t
+++ b/stream_ssl_verify_client.t
@@ -115,7 +115,7 @@ foreach my $name ('1.example.com', '2.ex
 TODO: {
 todo_skip 'leaves coredump', 1 unless $t->has_version('1.11.9');
 
-is(stream()->read(), ':', 'plain connection');
+is(stream('127.0.0.1:' . port(8080))->read(), ':', 'plain connection');
 
 }
 
--- a/stream_udp_upstream_least_conn.t
+++ b/stream_udp_upstream_least_conn.t
@@ -66,7 +66,7 @@ is(many(10), "$port1: 5, $port2: 5", 'ba
 
 my @sockets;
 for (1 .. 2) {
-	my $s = dgram();
+	my $s = dgram('127.0.0.1:' . port(8080));
 	$s->write('w');
 	push @sockets, $s;
 }
@@ -82,7 +82,7 @@ sub many {
 	my (%ports);
 
 	for (1 .. $count) {
-		if (dgram()->io('.') =~ /(\d+)/) {
+		if (dgram('127.0.0.1:' . port(8080))->io('.') =~ /(\d+)/) {
 			$ports{$1} = 0 unless defined $ports{$1};
 			$ports{$1}++;
 		}
--- a/stream_upstream_least_conn.t
+++ b/stream_upstream_least_conn.t
@@ -65,7 +65,7 @@ is(many(10), "$port1: 5, $port2: 5", 'ba
 
 my @sockets;
 for (1 .. 2) {
-	my $s = stream();
+	my $s = stream('127.0.0.1:' . port(8080));
 	$s->write('w');
 	push @sockets, $s;
 }
@@ -81,7 +81,7 @@ sub many {
 	my (%ports);
 
 	for (1 .. $count) {
-		if (stream()->io('.') =~ /(\d+)/) {
+		if (stream('127.0.0.1:' . port(8080))->io('.') =~ /(\d+)/) {
 			$ports{$1} = 0 unless defined $ports{$1};
 			$ports{$1}++;
 		}
--- a/stream_variables.t
+++ b/stream_variables.t
@@ -81,7 +81,8 @@ EOF
 ###############################################################################
 
 chomp(my $hostname = lc `hostname`);
-like(stream()->read(), qr/^\d+:[\d.]+:$hostname:\d+:0$/, 'vars');
+like(stream('127.0.0.1:' . port(8080))->read(),
+	qr/^\d+:[\d.]+:$hostname:\d+:0$/, 'vars');
 
 my $dport = port(8081);
 my $s = stream("127.0.0.1:$dport");