# HG changeset patch # User Sergey Kandaurov # Date 1618249097 -10800 # Node ID e57bb42241310c26b21a2d05fff04273d25fe79d # Parent 489484af31eba888c12049509d405df55356ddf3 Tests: upstream keepalive_time tests. diff --git a/upstream_keepalive.t b/upstream_keepalive.t --- a/upstream_keepalive.t +++ b/upstream_keepalive.t @@ -3,7 +3,7 @@ # (C) Sergey Kandaurov # (C) Nginx, Inc. -# Tests for upstream keepalive, keepalive_requests and keepalive_timeout. +# Tests for upstream keepalive directives. ############################################################################### @@ -22,7 +22,7 @@ use Test::Nginx; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http proxy upstream_keepalive/)->plan(7) +my $t = Test::Nginx->new()->has(qw/http proxy upstream_keepalive/) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -42,6 +42,12 @@ http { keepalive_timeout 2s; } + upstream time { + server 127.0.0.1:8081; + keepalive 1; + keepalive_time 2s; + } + server { listen 127.0.0.1:8080; server_name localhost; @@ -52,6 +58,10 @@ http { location / { proxy_pass http://backend; } + + location /time { + proxy_pass http://time/; + } } server { @@ -67,11 +77,11 @@ http { EOF $t->write_file('index.html', 'SEE-THIS'); -$t->run(); +$t->try_run('no keepalive_time')->plan(11); ############################################################################### -my ($r, $n); +my ($r, $n, $m); # keepalive_requests @@ -82,12 +92,20 @@ like(http_get('/'), qr/X-Connection: $n. like(http_get('/'), qr/X-Connection: (?!$n).*SEE/ms, 'keepalive requests'); http_get('/?close'); -# keepalive_timeout +# keepalive_timeout, keepalive_time like($r = http_get('/'), qr/SEE-THIS/, 'request timer'); $r =~ m/X-Connection: (\d+)/; $n = $1; +like($r = http_get('/time'), qr/SEE-THIS/, 'request time'); +$r =~ m/X-Connection: (\d+)/; $m = $1; + like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive timer'); +like(http_get('/time'), qr/X-Connection: $m.*SEE/ms, 'keepalive time'); + select undef, undef, undef, 2.5; + like(http_get('/'), qr/X-Connection: (?!$n).*SEE/ms, 'keepalive timeout'); +like(http_get('/time'), qr/X-Connection: $m.*SEE/ms, 'keepalive time last'); +like(http_get('/time'), qr/X-Connection: (?!$m).*SEE/ms, 'keepalive time new'); ###############################################################################