# HG changeset patch # User Sergey Kandaurov # Date 1432122183 -10800 # Node ID 7d6db4ac6ab090da55d39460aa678ae663f96db6 # Parent 5276aceb32a6e7d2edc654cd8a8e4b0717b7875d Tests: proxy_upgrade.t tests for bytes sent to a client. diff --git a/proxy_upgrade.t b/proxy_upgrade.t --- a/proxy_upgrade.t +++ b/proxy_upgrade.t @@ -28,7 +28,7 @@ select STDERR; $| = 1; 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 @@ events { 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 @@ http { EOF +my $d = $t->testdir(); + $t->run_daemon(\&upgrade_fake_daemon); $t->run(); @@ -67,6 +72,7 @@ EOF # establish connection +my @r; my $s = upgrade_connect(); ok($s, "handshake"); @@ -96,6 +102,7 @@ SKIP: { } } +push @r, $s ? ${*$s}->{_upgrade_private}->{r} : 'failed'; undef $s; # establish connection with some pipelined data @@ -113,6 +120,7 @@ SKIP: { 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 @@ undef $s; $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 @@ sub upgrade_getline { 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 @@ sub upgrade_getline { last unless $n; $h->{b} .= $buf; + $h->{r} += $n; if ($h->{b} =~ /^(.*?\x0a)(.*)/ms) { $h->{b} = $2;