comparison 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 a79bf84726af
children 97c8280de681
comparison
equal deleted inserted replaced
1239:4a825ec85c8d 1240:f7eb2875ed45
96 like(upgrade_read($s), qr/^(bar){16384}$/, "upgrade big response"); 96 like(upgrade_read($s), qr/^(bar){16384}$/, "upgrade big response");
97 97
98 # send multiple frames 98 # send multiple frames
99 99
100 for my $i (1 .. 10) { 100 for my $i (1 .. 10) {
101 upgrade_write($s, ('foo' x 16384) . $i); 101 upgrade_write($s, ('foo' x 16384) . $i, continue => 1);
102 upgrade_write($s, 'bazz' . $i); 102 upgrade_write($s, 'bazz' . $i, continue => $i != 10);
103 } 103 }
104 104
105 for my $i (1 .. 10) { 105 for my $i (1 .. 10) {
106 like(upgrade_read($s), qr/^(bar){16384}\d+$/, "upgrade $i"); 106 like(upgrade_read($s), qr/^(bar){16384}\d+$/, "upgrade $i");
107 is(upgrade_read($s), 'bazz' . $i, "upgrade small $i"); 107 is(upgrade_read($s), 'bazz' . $i, "upgrade small $i");
175 my $buf = "GET $uri HTTP/1.1" . CRLF 175 my $buf = "GET $uri HTTP/1.1" . CRLF
176 . "Host: localhost" . CRLF 176 . "Host: localhost" . CRLF
177 . ($opts{noheader} ? '' : "Upgrade: foo" . CRLF) 177 . ($opts{noheader} ? '' : "Upgrade: foo" . CRLF)
178 . "Connection: Upgrade" . CRLF . CRLF; 178 . "Connection: Upgrade" . CRLF . CRLF;
179 179
180 $buf .= $opts{message} . CRLF if defined $opts{message}; 180 $buf .= $opts{message} . CRLF . 'FIN' if defined $opts{message};
181 181
182 local $SIG{PIPE} = 'IGNORE'; 182 local $SIG{PIPE} = 'IGNORE';
183 183
184 log_out($buf); 184 log_out($buf);
185 $s->syswrite($buf); 185 $s->syswrite($buf);
235 } 235 }
236 }; 236 };
237 } 237 }
238 238
239 sub upgrade_write { 239 sub upgrade_write {
240 my ($s, $message) = @_; 240 my ($s, $message, %extra) = @_;
241 241
242 $message = $message . CRLF; 242 $message = $message . CRLF;
243 $message = $message . 'FIN' unless $extra{continue};
243 244
244 local $SIG{PIPE} = 'IGNORE'; 245 local $SIG{PIPE} = 'IGNORE';
245 246
246 $s->blocking(0); 247 $s->blocking(0);
247 while (IO::Select->new($s)->can_write(1.5)) { 248 while (IO::Select->new($s)->can_write(1.5)) {
323 next; 324 next;
324 } 325 }
325 326
326 $unfinished .= $chunk; 327 $unfinished .= $chunk;
327 328
328 if ($unfinished =~ m/\x0d?\x0a\z/) { 329 if ($unfinished =~ m/\x0d?\x0aFIN\z/) {
330 $unfinished =~ s/FIN\z//;
329 $unfinished =~ s/foo/bar/g; 331 $unfinished =~ s/foo/bar/g;
330 log2o($unfinished); 332 log2o($unfinished);
331 $buffer .= $unfinished; 333 $buffer .= $unfinished;
332 $unfinished = ''; 334 $unfinished = '';
333 } 335 }