comparison ssl_proxy_upgrade.t @ 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 0af58b78df35
children dbce8fb5f5f8
comparison
equal deleted inserted replaced
1239:4a825ec85c8d 1240:f7eb2875ed45
116 like(upgrade_read($s), qr/^(bar){16384}$/, "upgrade big response"); 116 like(upgrade_read($s), qr/^(bar){16384}$/, "upgrade big response");
117 117
118 # send multiple frames 118 # send multiple frames
119 119
120 for my $i (1 .. 10) { 120 for my $i (1 .. 10) {
121 upgrade_write($s, ('foo' x 16384) . $i); 121 upgrade_write($s, ('foo' x 16384) . $i, continue => 1);
122 upgrade_write($s, 'bazz' . $i); 122 upgrade_write($s, 'bazz' . $i, continue => $i != 10);
123 } 123 }
124 124
125 for my $i (1 .. 10) { 125 for my $i (1 .. 10) {
126 like(upgrade_read($s), qr/^(bar){16384}\d+$/, "upgrade $i"); 126 like(upgrade_read($s), qr/^(bar){16384}\d+$/, "upgrade $i");
127 is(upgrade_read($s), 'bazz' . $i, "upgrade small $i"); 127 is(upgrade_read($s), 'bazz' . $i, "upgrade small $i");
183 my $buf = "GET / HTTP/1.1" . CRLF 183 my $buf = "GET / HTTP/1.1" . CRLF
184 . "Host: localhost" . CRLF 184 . "Host: localhost" . CRLF
185 . ($opts{noheader} ? '' : "Upgrade: foo" . CRLF) 185 . ($opts{noheader} ? '' : "Upgrade: foo" . CRLF)
186 . "Connection: Upgrade" . CRLF . CRLF; 186 . "Connection: Upgrade" . CRLF . CRLF;
187 187
188 $buf .= $opts{message} . CRLF if defined $opts{message}; 188 $buf .= $opts{message} . CRLF . 'FIN' if defined $opts{message};
189 189
190 local $SIG{PIPE} = 'IGNORE'; 190 local $SIG{PIPE} = 'IGNORE';
191 191
192 log_out($buf); 192 log_out($buf);
193 $s->syswrite($buf); 193 $s->syswrite($buf);
249 } 249 }
250 }; 250 };
251 } 251 }
252 252
253 sub upgrade_write { 253 sub upgrade_write {
254 my ($s, $message) = @_; 254 my ($s, $message, %extra) = @_;
255 255
256 $message = $message . CRLF; 256 $message = $message . CRLF;
257 $message = $message . 'FIN' unless $extra{continue};
257 258
258 local $SIG{PIPE} = 'IGNORE'; 259 local $SIG{PIPE} = 'IGNORE';
259 260
260 $s->blocking(0); 261 $s->blocking(0);
261 while (IO::Select->new($s)->can_write(1.5)) { 262 while (IO::Select->new($s)->can_write(1.5)) {
340 next; 341 next;
341 } 342 }
342 343
343 $unfinished .= $chunk; 344 $unfinished .= $chunk;
344 345
345 if ($unfinished =~ m/\x0d?\x0a\z/) { 346 if ($unfinished =~ m/\x0d?\x0aFIN\z/) {
347 $unfinished =~ s/FIN\z//;
346 $unfinished =~ s/foo/bar/g; 348 $unfinished =~ s/foo/bar/g;
347 log2o($unfinished); 349 log2o($unfinished);
348 $buffer .= $unfinished; 350 $buffer .= $unfinished;
349 $unfinished = ''; 351 $unfinished = '';
350 } 352 }