Mercurial > hg > nginx-tests
changeset 732:984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
The proxy_connect_timeout timer should be disabled after socket was connected.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 05 Oct 2015 13:19:45 +0300 |
parents | cf9183219c59 |
children | 3b25ee897439 |
files | proxy.t proxy_ssl.t stream_proxy.t stream_proxy_ssl.t |
diffstat | 4 files changed, 43 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/proxy.t Thu Oct 01 19:54:33 2015 +0300 +++ b/proxy.t Mon Oct 05 13:19:45 2015 +0300 @@ -21,7 +21,7 @@ select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(4); +my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(5); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -42,6 +42,7 @@ location / { proxy_pass http://127.0.0.1:8081; proxy_read_timeout 1s; + proxy_connect_timeout 1s; } location /var { @@ -65,6 +66,12 @@ like(http_get('/var?b=127.0.0.1:8081/'), qr/SEE-THIS/, 'proxy with variables'); +my $s = http('', start => 1); + +sleep 2; + +like(http_get('/', socket => $s), qr/200 OK/, 'proxy connect timeout'); + ############################################################################### sub http_daemon {
--- a/proxy_ssl.t Thu Oct 01 19:54:33 2015 +0300 +++ b/proxy_ssl.t Mon Oct 05 13:19:45 2015 +0300 @@ -22,7 +22,7 @@ select STDOUT; $| = 1; my $t = Test::Nginx->new()->has(qw/http proxy http_ssl/)->has_daemon('openssl') - ->plan(4)->write_file_expand('nginx.conf', <<'EOF'); + ->plan(5)->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -59,6 +59,11 @@ proxy_pass https://127.0.0.1:8081/; proxy_ssl_session_reuse off; } + + location /timeout { + proxy_pass https://127.0.0.1:8081/; + proxy_connect_timeout 1s; + } } } @@ -93,4 +98,10 @@ like(http_get('/ssl_reuse'), qr/200 OK.*X-Session: \./s, 'ssl reuse session'); like(http_get('/ssl_reuse'), qr/200 OK.*X-Session: r/s, 'ssl reuse session 2'); +my $s = http('', start => 1); + +sleep 2; + +like(http_get('/timeout', socket => $s), qr/200 OK/, 'proxy connect timeout'); + ###############################################################################
--- a/stream_proxy.t Thu Oct 01 19:54:33 2015 +0300 +++ b/stream_proxy.t Mon Oct 05 13:19:45 2015 +0300 @@ -24,7 +24,7 @@ select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/stream/)->plan(4) +my $t = Test::Nginx->new()->has(qw/stream/)->plan(5) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -63,6 +63,13 @@ stream_write($s, 'test'); is(stream_read($s), '', 'proxy connection closed'); +$s = stream_connect(); + +sleep 2; + +stream_write($s, 'foo'); +is(stream_read($s), 'bar', 'proxy connect timeout'); + ############################################################################### sub stream_connect {
--- a/stream_proxy_ssl.t Thu Oct 01 19:54:33 2015 +0300 +++ b/stream_proxy_ssl.t Mon Oct 05 13:19:45 2015 +0300 @@ -23,7 +23,7 @@ select STDOUT; $| = 1; my $t = Test::Nginx->new()->has(qw/stream stream_ssl http http_ssl/) - ->has_daemon('openssl')->plan(4); + ->has_daemon('openssl')->plan(5); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -37,6 +37,7 @@ stream { proxy_ssl on; proxy_ssl_session_reuse on; + proxy_connect_timeout 1s; server { listen 127.0.0.1:8080; @@ -103,6 +104,19 @@ like(http_get('/', socket => getconn('127.0.0.1:8081')), qr/200 OK.*X-Session: r/s, 'ssl reuse session 2'); +my $s = http('', start => 1); + +sleep 2; + +my $r = http_get('/', socket => $s); + +TODO: { +todo_skip 'not yet', 1 unless $r; + +like($r, qr/200 OK/, 'proxy connect timeout'); + +} + ############################################################################### sub getconn {