Mercurial > hg > nginx-tests
changeset 584:7d6db4ac6ab0
Tests: proxy_upgrade.t tests for bytes sent to a client.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 20 May 2015 14:43:03 +0300 |
parents | 5276aceb32a6 |
children | 5bb19f7448b5 |
files | proxy_upgrade.t |
diffstat | 1 files changed, 22 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/proxy_upgrade.t Wed May 20 14:42:51 2015 +0300 +++ b/proxy_upgrade.t Wed May 20 14:43:03 2015 +0300 @@ -28,7 +28,7 @@ select STDOUT; $| = 1; my $t = Test::Nginx->new()->has(qw/http proxy/) - ->write_file_expand('nginx.conf', <<'EOF')->plan(27); + ->write_file_expand('nginx.conf', <<'EOF')->plan(30); %%TEST_GLOBALS%% @@ -40,6 +40,9 @@ http { %%TEST_GLOBALS_HTTP%% + log_format test "$bytes_sent $body_bytes_sent"; + access_log %%TESTDIR%%/cc.log test; + server { listen 127.0.0.1:8080; server_name localhost; @@ -57,6 +60,8 @@ EOF +my $d = $t->testdir(); + $t->run_daemon(\&upgrade_fake_daemon); $t->run(); @@ -67,6 +72,7 @@ # establish connection +my @r; my $s = upgrade_connect(); ok($s, "handshake"); @@ -96,6 +102,7 @@ } } +push @r, $s ? ${*$s}->{_upgrade_private}->{r} : 'failed'; undef $s; # establish connection with some pipelined data @@ -113,6 +120,7 @@ is(upgrade_read($s), "bar", "next to pipelined"); } +push @r, $s ? ${*$s}->{_upgrade_private}->{r} : 'failed'; undef $s; # connection should not be upgraded unless upgrade was actually @@ -121,6 +129,17 @@ $s = upgrade_connect(noheader => 1); ok(!$s, "handshake noupgrade"); +# bytes sent on upgraded connection +# verify with 1) data actually read by client, 2) expected data from backend + +$t->stop(); + +open my $f, '<', "$d/cc.log" or die "Can't open cc.log: $!"; + +is($f->getline(), shift (@r) . " 540793\n", 'log - bytes'); +is($f->getline(), shift (@r) . " 22\n", 'log - bytes pipelined'); +is($f->getline(), "0 0\n", 'log - bytes noupgrade'); + ############################################################################### sub upgrade_connect { @@ -175,7 +194,7 @@ my ($s) = @_; my ($h, $buf, $line); - ${*$s}->{_upgrade_private} ||= { b => ''}; + ${*$s}->{_upgrade_private} ||= { b => '', r => 0 }; $h = ${*$s}->{_upgrade_private}; if ($h->{b} =~ /^(.*?\x0a)(.*)/ms) { @@ -189,6 +208,7 @@ last unless $n; $h->{b} .= $buf; + $h->{r} += $n; if ($h->{b} =~ /^(.*?\x0a)(.*)/ms) { $h->{b} = $2;