# HG changeset patch # User Sergey Kandaurov # Date 1444040385 -10800 # Node ID 984bfe661ccea7f8c248f36962ee0a60bcec0adb # Parent cf9183219c592dabc25ea64374f66976f31a154a Tests: stream and http proxy_connect_timeout tests. The proxy_connect_timeout timer should be disabled after socket was connected. diff --git a/proxy.t b/proxy.t --- a/proxy.t +++ b/proxy.t @@ -21,7 +21,7 @@ use Test::Nginx; 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 @@ http { location / { proxy_pass http://127.0.0.1:8081; proxy_read_timeout 1s; + proxy_connect_timeout 1s; } location /var { @@ -65,6 +66,12 @@ unlike(http_head('/'), qr/SEE-THIS/, 'pr 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 { diff --git a/proxy_ssl.t b/proxy_ssl.t --- a/proxy_ssl.t +++ b/proxy_ssl.t @@ -22,7 +22,7 @@ select STDERR; $| = 1; 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 @@ http { 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'), qr/200 OK.*X-Sess 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'); + ############################################################################### diff --git a/stream_proxy.t b/stream_proxy.t --- a/stream_proxy.t +++ b/stream_proxy.t @@ -24,7 +24,7 @@ use Test::Nginx; 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 @@ is(stream_read($s), 'close', 'proxy conn 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 { diff --git a/stream_proxy_ssl.t b/stream_proxy_ssl.t --- a/stream_proxy_ssl.t +++ b/stream_proxy_ssl.t @@ -23,7 +23,7 @@ select STDERR; $| = 1; 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 @@ events { 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('12 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 {