Mercurial > hg > nginx-tests
comparison proxy_variables.t @ 952:e9064d691790
Tests: converted tests to run in parallel.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Tue, 21 Jun 2016 16:39:13 +0300 |
parents | dbe5bc4b8b39 |
children | 882267679006 |
comparison
equal
deleted
inserted
replaced
951:9361c7eddfc1 | 952:e9064d691790 |
---|---|
34 | 34 |
35 http { | 35 http { |
36 %%TEST_GLOBALS_HTTP%% | 36 %%TEST_GLOBALS_HTTP%% |
37 | 37 |
38 upstream u { | 38 upstream u { |
39 server 127.0.0.1:8081; | 39 server 127.0.0.1:%%PORT_1%%; |
40 server 127.0.0.1:8081; | 40 server 127.0.0.1:%%PORT_1%%; |
41 } | 41 } |
42 | 42 |
43 log_format time '$upstream_connect_time:$upstream_header_time:' | 43 log_format time '$upstream_connect_time:$upstream_header_time:' |
44 '$upstream_response_time'; | 44 '$upstream_response_time'; |
45 | 45 |
46 server { | 46 server { |
47 listen 127.0.0.1:8080; | 47 listen 127.0.0.1:%%PORT_0%%; |
48 server_name localhost; | 48 server_name localhost; |
49 | 49 |
50 add_header X-Connect $upstream_connect_time; | 50 add_header X-Connect $upstream_connect_time; |
51 add_header X-Header $upstream_header_time; | 51 add_header X-Header $upstream_header_time; |
52 add_header X-Response $upstream_response_time; | 52 add_header X-Response $upstream_response_time; |
53 | 53 |
54 location / { | 54 location / { |
55 proxy_pass http://127.0.0.1:8081; | 55 proxy_pass http://127.0.0.1:%%PORT_1%%; |
56 access_log %%TESTDIR%%/time.log time; | 56 access_log %%TESTDIR%%/time.log time; |
57 } | 57 } |
58 | 58 |
59 location /pnu { | 59 location /pnu { |
60 proxy_pass http://u/bad; | 60 proxy_pass http://u/bad; |
61 } | 61 } |
62 | 62 |
63 location /vars { | 63 location /vars { |
64 proxy_pass http://127.0.0.1:8080/stub; | 64 proxy_pass http://127.0.0.1:%%PORT_0%%/stub; |
65 | 65 |
66 add_header X-Proxy-Host $proxy_host; | 66 add_header X-Proxy-Host $proxy_host; |
67 add_header X-Proxy-Port $proxy_port; | 67 add_header X-Proxy-Port $proxy_port; |
68 add_header X-Proxy-Forwarded $proxy_add_x_forwarded_for; | 68 add_header X-Proxy-Forwarded $proxy_add_x_forwarded_for; |
69 } | 69 } |
73 } | 73 } |
74 | 74 |
75 EOF | 75 EOF |
76 | 76 |
77 $t->write_file('stub', ''); | 77 $t->write_file('stub', ''); |
78 $t->run_daemon(\&http_daemon, 8081); | 78 $t->run_daemon(\&http_daemon, port(1)); |
79 $t->try_run('no upstream_connect_time')->plan(18); | 79 $t->try_run('no upstream_connect_time')->plan(18); |
80 | 80 |
81 $t->waitforsocket('127.0.0.1:8081'); | 81 $t->waitforsocket('127.0.0.1:' . port(1)); |
82 | 82 |
83 ############################################################################### | 83 ############################################################################### |
84 | 84 |
85 my $re = qr/(\d\.\d{3})/; | 85 my $re = qr/(\d\.\d{3})/; |
86 my $p0 = port(0); | |
86 my ($ct, $ht, $rt, $ct2, $ht2, $rt2); | 87 my ($ct, $ht, $rt, $ct2, $ht2, $rt2); |
87 | 88 |
88 like(http_get('/vars'), qr/X-Proxy-Host:\s127\.0\.0\.1:8080/, 'proxy_host'); | 89 like(http_get('/vars'), qr/X-Proxy-Host:\s127\.0\.0\.1:$p0/, 'proxy_host'); |
89 like(http_get('/vars'), qr/X-Proxy-Port:\s8080/, 'proxy_port'); | 90 like(http_get('/vars'), qr/X-Proxy-Port:\s$p0/, 'proxy_port'); |
90 like(http_xff('/vars', '192.0.2.1'), qr/X-Proxy-Forwarded:.*192\.0\.2\.1/, | 91 like(http_xff('/vars', '192.0.2.1'), qr/X-Proxy-Forwarded:.*192\.0\.2\.1/, |
91 'proxy_add_x_forwarded_for'); | 92 'proxy_add_x_forwarded_for'); |
92 | 93 |
93 ($ct, $ht) = get('/header'); | 94 ($ct, $ht) = get('/header'); |
94 cmp_ok($ct, '<', 1, 'connect time - slow response header'); | 95 cmp_ok($ct, '<', 1, 'connect time - slow response header'); |