Mercurial > hg > nginx-tests
comparison upstream_keepalive.t @ 1671:e57bb4224131
Tests: upstream keepalive_time tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 12 Apr 2021 20:38:17 +0300 |
parents | 144c6ce732e4 |
children | 5ac6efbe5552 |
comparison
equal
deleted
inserted
replaced
1670:489484af31eb | 1671:e57bb4224131 |
---|---|
1 #!/usr/bin/perl | 1 #!/usr/bin/perl |
2 | 2 |
3 # (C) Sergey Kandaurov | 3 # (C) Sergey Kandaurov |
4 # (C) Nginx, Inc. | 4 # (C) Nginx, Inc. |
5 | 5 |
6 # Tests for upstream keepalive, keepalive_requests and keepalive_timeout. | 6 # Tests for upstream keepalive directives. |
7 | 7 |
8 ############################################################################### | 8 ############################################################################### |
9 | 9 |
10 use warnings; | 10 use warnings; |
11 use strict; | 11 use strict; |
20 ############################################################################### | 20 ############################################################################### |
21 | 21 |
22 select STDERR; $| = 1; | 22 select STDERR; $| = 1; |
23 select STDOUT; $| = 1; | 23 select STDOUT; $| = 1; |
24 | 24 |
25 my $t = Test::Nginx->new()->has(qw/http proxy upstream_keepalive/)->plan(7) | 25 my $t = Test::Nginx->new()->has(qw/http proxy upstream_keepalive/) |
26 ->write_file_expand('nginx.conf', <<'EOF'); | 26 ->write_file_expand('nginx.conf', <<'EOF'); |
27 | 27 |
28 %%TEST_GLOBALS%% | 28 %%TEST_GLOBALS%% |
29 | 29 |
30 daemon off; | 30 daemon off; |
40 keepalive 1; | 40 keepalive 1; |
41 keepalive_requests 3; | 41 keepalive_requests 3; |
42 keepalive_timeout 2s; | 42 keepalive_timeout 2s; |
43 } | 43 } |
44 | 44 |
45 upstream time { | |
46 server 127.0.0.1:8081; | |
47 keepalive 1; | |
48 keepalive_time 2s; | |
49 } | |
50 | |
45 server { | 51 server { |
46 listen 127.0.0.1:8080; | 52 listen 127.0.0.1:8080; |
47 server_name localhost; | 53 server_name localhost; |
48 | 54 |
49 proxy_http_version 1.1; | 55 proxy_http_version 1.1; |
50 proxy_set_header Connection $args; | 56 proxy_set_header Connection $args; |
51 | 57 |
52 location / { | 58 location / { |
53 proxy_pass http://backend; | 59 proxy_pass http://backend; |
60 } | |
61 | |
62 location /time { | |
63 proxy_pass http://time/; | |
54 } | 64 } |
55 } | 65 } |
56 | 66 |
57 server { | 67 server { |
58 listen 127.0.0.1:8081; | 68 listen 127.0.0.1:8081; |
65 } | 75 } |
66 | 76 |
67 EOF | 77 EOF |
68 | 78 |
69 $t->write_file('index.html', 'SEE-THIS'); | 79 $t->write_file('index.html', 'SEE-THIS'); |
70 $t->run(); | 80 $t->try_run('no keepalive_time')->plan(11); |
71 | 81 |
72 ############################################################################### | 82 ############################################################################### |
73 | 83 |
74 my ($r, $n); | 84 my ($r, $n, $m); |
75 | 85 |
76 # keepalive_requests | 86 # keepalive_requests |
77 | 87 |
78 like($r = http_get('/'), qr/SEE-THIS/, 'request'); | 88 like($r = http_get('/'), qr/SEE-THIS/, 'request'); |
79 $r =~ m/X-Connection: (\d+)/; $n = $1; | 89 $r =~ m/X-Connection: (\d+)/; $n = $1; |
80 like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive'); | 90 like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive'); |
81 like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive again'); | 91 like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive again'); |
82 like(http_get('/'), qr/X-Connection: (?!$n).*SEE/ms, 'keepalive requests'); | 92 like(http_get('/'), qr/X-Connection: (?!$n).*SEE/ms, 'keepalive requests'); |
83 http_get('/?close'); | 93 http_get('/?close'); |
84 | 94 |
85 # keepalive_timeout | 95 # keepalive_timeout, keepalive_time |
86 | 96 |
87 like($r = http_get('/'), qr/SEE-THIS/, 'request timer'); | 97 like($r = http_get('/'), qr/SEE-THIS/, 'request timer'); |
88 $r =~ m/X-Connection: (\d+)/; $n = $1; | 98 $r =~ m/X-Connection: (\d+)/; $n = $1; |
99 like($r = http_get('/time'), qr/SEE-THIS/, 'request time'); | |
100 $r =~ m/X-Connection: (\d+)/; $m = $1; | |
101 | |
89 like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive timer'); | 102 like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive timer'); |
103 like(http_get('/time'), qr/X-Connection: $m.*SEE/ms, 'keepalive time'); | |
104 | |
90 select undef, undef, undef, 2.5; | 105 select undef, undef, undef, 2.5; |
106 | |
91 like(http_get('/'), qr/X-Connection: (?!$n).*SEE/ms, 'keepalive timeout'); | 107 like(http_get('/'), qr/X-Connection: (?!$n).*SEE/ms, 'keepalive timeout'); |
108 like(http_get('/time'), qr/X-Connection: $m.*SEE/ms, 'keepalive time last'); | |
109 like(http_get('/time'), qr/X-Connection: (?!$m).*SEE/ms, 'keepalive time new'); | |
92 | 110 |
93 ############################################################################### | 111 ############################################################################### |