changeset 1240:f7eb2875ed45

Tests: avoid interleaved output in Upgrade handling tests. When the testing script is run in verbose mode by prove that redirects stdout, a garbled verbose mode line from backend can be produced that incorporates TAP output of an individual test result, which eventually breaks the testing plan. Notably, this happens when testing sending multiple frames if backend started to respond before all frames were received. This is possible due to the line boundary used as an indicator of last bytes to receive before starting to send. The fix is to amend the only last frame of many specially, for that purpose.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 15 Nov 2017 20:16:09 +0300
parents 4a825ec85c8d
children 6b4c0c80cd00
files proxy_upgrade.t ssl_proxy_upgrade.t
diffstat 2 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/proxy_upgrade.t
+++ b/proxy_upgrade.t
@@ -98,8 +98,8 @@ SKIP: {
 	# send multiple frames
 
 	for my $i (1 .. 10) {
-		upgrade_write($s, ('foo' x 16384) . $i);
-		upgrade_write($s, 'bazz' . $i);
+		upgrade_write($s, ('foo' x 16384) . $i, continue => 1);
+		upgrade_write($s, 'bazz' . $i, continue => $i != 10);
 	}
 
 	for my $i (1 .. 10) {
@@ -177,7 +177,7 @@ sub upgrade_connect {
 		. ($opts{noheader} ? '' : "Upgrade: foo" . CRLF)
 		. "Connection: Upgrade" . CRLF . CRLF;
 
-	$buf .= $opts{message} . CRLF if defined $opts{message};
+	$buf .= $opts{message} . CRLF . 'FIN' if defined $opts{message};
 
 	local $SIG{PIPE} = 'IGNORE';
 
@@ -237,9 +237,10 @@ sub upgrade_getline {
 }
 
 sub upgrade_write {
-	my ($s, $message) = @_;
+	my ($s, $message, %extra) = @_;
 
 	$message = $message . CRLF;
+	$message = $message . 'FIN' unless $extra{continue};
 
 	local $SIG{PIPE} = 'IGNORE';
 
@@ -325,7 +326,8 @@ sub upgrade_handle_client {
 
 			$unfinished .= $chunk;
 
-			if ($unfinished =~ m/\x0d?\x0a\z/) {
+			if ($unfinished =~ m/\x0d?\x0aFIN\z/) {
+				$unfinished =~ s/FIN\z//;
 				$unfinished =~ s/foo/bar/g;
 				log2o($unfinished);
 				$buffer .= $unfinished;
--- a/ssl_proxy_upgrade.t
+++ b/ssl_proxy_upgrade.t
@@ -118,8 +118,8 @@ SKIP: {
 	# send multiple frames
 
 	for my $i (1 .. 10) {
-		upgrade_write($s, ('foo' x 16384) . $i);
-		upgrade_write($s, 'bazz' . $i);
+		upgrade_write($s, ('foo' x 16384) . $i, continue => 1);
+		upgrade_write($s, 'bazz' . $i, continue => $i != 10);
 	}
 
 	for my $i (1 .. 10) {
@@ -185,7 +185,7 @@ sub upgrade_connect {
 		. ($opts{noheader} ? '' : "Upgrade: foo" . CRLF)
 		. "Connection: Upgrade" . CRLF . CRLF;
 
-	$buf .= $opts{message} . CRLF if defined $opts{message};
+	$buf .= $opts{message} . CRLF . 'FIN' if defined $opts{message};
 
 	local $SIG{PIPE} = 'IGNORE';
 
@@ -251,9 +251,10 @@ sub upgrade_getline {
 }
 
 sub upgrade_write {
-	my ($s, $message) = @_;
+	my ($s, $message, %extra) = @_;
 
 	$message = $message . CRLF;
+	$message = $message . 'FIN' unless $extra{continue};
 
 	local $SIG{PIPE} = 'IGNORE';
 
@@ -342,7 +343,8 @@ sub upgrade_handle_client {
 
 			$unfinished .= $chunk;
 
-			if ($unfinished =~ m/\x0d?\x0a\z/) {
+			if ($unfinished =~ m/\x0d?\x0aFIN\z/) {
+				$unfinished =~ s/FIN\z//;
 				$unfinished =~ s/foo/bar/g;
 				log2o($unfinished);
 				$buffer .= $unfinished;