Mercurial > hg > nginx-tests
comparison upstream_keepalive.t @ 1365:992044531283
Tests: upstream keepalive_requests and keepalive_timeout tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 14 Aug 2018 17:01:32 +0300 |
parents | |
children | 144c6ce732e4 |
comparison
equal
deleted
inserted
replaced
1364:62e2baa3bc60 | 1365:992044531283 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for upstream keepalive, keepalive_requests and keepalive_timeout. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http proxy upstream_keepalive/) | |
26 ->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 http { | |
36 %%TEST_GLOBALS_HTTP%% | |
37 | |
38 upstream backend { | |
39 server 127.0.0.1:8081; | |
40 keepalive 1; | |
41 keepalive_requests 3; | |
42 keepalive_timeout 2s; | |
43 } | |
44 | |
45 server { | |
46 listen 127.0.0.1:8080; | |
47 server_name localhost; | |
48 | |
49 proxy_http_version 1.1; | |
50 proxy_set_header Connection $args; | |
51 | |
52 location / { | |
53 proxy_pass http://backend; | |
54 } | |
55 } | |
56 | |
57 server { | |
58 listen 127.0.0.1:8081; | |
59 server_name localhost; | |
60 | |
61 location / { | |
62 add_header X-Connection $connection; | |
63 } | |
64 } | |
65 } | |
66 | |
67 EOF | |
68 | |
69 $t->write_file('index.html', 'SEE-THIS'); | |
70 $t->try_run('no keepalive_requests')->plan(7); | |
71 | |
72 ############################################################################### | |
73 | |
74 my ($r, $n); | |
75 | |
76 # keepalive_requests | |
77 | |
78 like($r = http_get('/'), qr/SEE-THIS/, 'request'); | |
79 $r =~ m/X-Connection: (\d+)/; $n = $1; | |
80 like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive'); | |
81 like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive again'); | |
82 like(http_get('/'), qr/X-Connection: (?!$n).*SEE/ms, 'keepalive requests'); | |
83 http_get('/?close'); | |
84 | |
85 # keepalive_timeout | |
86 | |
87 like($r = http_get('/'), qr/SEE-THIS/, 'request timer'); | |
88 $r =~ m/X-Connection: (\d+)/; $n = $1; | |
89 like(http_get('/'), qr/X-Connection: $n.*SEE/ms, 'keepalive timer'); | |
90 select undef, undef, undef, 2.5; | |
91 like(http_get('/'), qr/X-Connection: (?!$n).*SEE/ms, 'keepalive timeout'); | |
92 | |
93 ############################################################################### |