Mercurial > hg > nginx-tests
annotate upstream_keepalive.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 5ac6efbe5552 |
children |
rev | line source |
---|---|
1365
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
1671
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
6 # Tests for upstream keepalive directives. |
1365
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
1671
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy upstream_keepalive/) |
1365
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 http { |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 upstream backend { |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 server 127.0.0.1:8081; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 keepalive 1; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 keepalive_requests 3; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 keepalive_timeout 2s; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 } |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
1671
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
45 upstream time { |
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
46 server 127.0.0.1:8081; |
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
47 keepalive 1; |
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
48 keepalive_time 2s; |
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
49 } |
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
50 |
1365
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server { |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 listen 127.0.0.1:8080; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 server_name localhost; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 proxy_http_version 1.1; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 proxy_set_header Connection $args; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 location / { |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 proxy_pass http://backend; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 } |
1671
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
61 |
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
62 location /time { |
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
63 proxy_pass http://time/; |
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
64 } |
1365
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 server { |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 listen 127.0.0.1:8081; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 server_name localhost; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 location / { |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 add_header X-Connection $connection; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 } |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 } |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 } |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 EOF |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 $t->write_file('index.html', 'SEE-THIS'); |
1693
5ac6efbe5552
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1671
diff
changeset
|
80 $t->run()->plan(11); |
1365
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 ############################################################################### |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
1671
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
84 my ($r, $n, $m); |
1365
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 # keepalive_requests |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 like($r = http_get('/'), qr/SEE-THIS/, 'request'); |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 $r =~ m/X-Connection: (\d+)/; $n = $1; |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive'); |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive again'); |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 like(http_get('/'), qr/X-Connection: (?!$n).*SEE/ms, 'keepalive requests'); |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 http_get('/?close'); |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 |
1671
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
95 # keepalive_timeout, keepalive_time |
1365
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 like($r = http_get('/'), qr/SEE-THIS/, 'request timer'); |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 $r =~ m/X-Connection: (\d+)/; $n = $1; |
1671
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
99 like($r = http_get('/time'), qr/SEE-THIS/, 'request time'); |
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
100 $r =~ m/X-Connection: (\d+)/; $m = $1; |
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
101 |
1365
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive timer'); |
1671
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
103 like(http_get('/time'), qr/X-Connection: $m.*SEE/ms, 'keepalive time'); |
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
104 |
1365
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 select undef, undef, undef, 2.5; |
1671
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
106 |
1365
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 like(http_get('/'), qr/X-Connection: (?!$n).*SEE/ms, 'keepalive timeout'); |
1671
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
108 like(http_get('/time'), qr/X-Connection: $m.*SEE/ms, 'keepalive time last'); |
e57bb4224131
Tests: upstream keepalive_time tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
109 like(http_get('/time'), qr/X-Connection: (?!$m).*SEE/ms, 'keepalive time new'); |
1365
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 |
992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 ############################################################################### |