Mercurial > hg > nginx-tests
annotate stream_status_variable.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | f3ba4c74de31 |
children |
rev | line source |
---|---|
1025
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream status variable. |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::Stream qw/ stream /; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_return stream_access/) |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ->has(qw/stream_limit_conn/); |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1251
diff
changeset
|
39 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1251
diff
changeset
|
40 |
1025
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 log_format status $status; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 limit_conn_zone $binary_remote_addr zone=zone:1m; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 server { |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 listen 127.0.0.1:8080; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 return SEE-THIS; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 access_log %%TESTDIR%%/200.log status; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server { |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 listen 127.0.0.1:8081; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 return SEE-THIS; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 deny all; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 access_log %%TESTDIR%%/403.log status; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server { |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 listen 127.0.0.1:8082; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 proxy_pass 127.0.0.1:8083; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 access_log %%TESTDIR%%/502.log status; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 proxy_connect_timeout 0; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 server { |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 listen 127.0.0.1:8084; |
1222
75a83f36cff0
Tests: made all tests in stream_status_variable.t work on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1025
diff
changeset
|
68 proxy_pass example.com:$remote_port; |
1025
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 access_log %%TESTDIR%%/500.log status; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 } |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 server { |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 listen 127.0.0.1:8085; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 limit_conn zone 1; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 proxy_pass 127.0.0.1:8086; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 access_log %%TESTDIR%%/503.log status; |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 } |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 server { |
1228
31045e639732
Tests: fixed stream_status_variable.t transient failure on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1222
diff
changeset
|
80 listen 127.0.0.1:8086 proxy_protocol; |
1025
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 return SEE-THIS; |
1229
6979619de0e3
Tests: added stream $status test with invalid PROXY header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1228
diff
changeset
|
82 access_log %%TESTDIR%%/400.log status; |
1025
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 } |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 } |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 EOF |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1231
diff
changeset
|
88 $t->run()->plan(6); |
1025
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 ############################################################################### |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 stream('127.0.0.1:' . port(8080))->read(); |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 stream('127.0.0.1:' . port(8081))->read(); |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 stream('127.0.0.1:' . port(8082))->read(); |
1222
75a83f36cff0
Tests: made all tests in stream_status_variable.t work on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1025
diff
changeset
|
95 stream('127.0.0.1:' . port(8084))->read(); |
1025
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 my $s = stream('127.0.0.1:' . port(8085)); |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 stream('127.0.0.1:' . port(8085))->read(); |
1231
5ceb07e20515
Tests: fixed race in stream_status_variable.t on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1229
diff
changeset
|
99 $s->io('PROXY INVALID'); |
1025
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 $t->stop(); |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 is($t->read_file('200.log'), "200\n", 'stream status 200'); |
1229
6979619de0e3
Tests: added stream $status test with invalid PROXY header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1228
diff
changeset
|
104 is($t->read_file('400.log'), "400\n", 'stream status 400'); |
1025
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 is($t->read_file('403.log'), "403\n", 'stream status 403'); |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 is($t->read_file('500.log'), "500\n", 'stream status 500'); |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 is($t->read_file('502.log'), "502\n", 'stream status 502'); |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 is($t->read_file('503.log'), "503\n200\n", 'stream status 503'); |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
94f8cd9b41dc
Tests: stream $status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 ############################################################################### |