Mercurial > hg > nginx-tests
comparison stream_status_variable.t @ 1025:94f8cd9b41dc
Tests: stream $status tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 05 Sep 2016 22:57:44 +0300 |
parents | |
children | 75a83f36cff0 |
comparison
equal
deleted
inserted
replaced
1024:91e64c1ceec9 | 1025:94f8cd9b41dc |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for stream status variable. | |
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 use Test::Nginx::Stream qw/ stream /; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 my $t = Test::Nginx->new()->has(qw/stream stream_return stream_access/) | |
27 ->has(qw/stream_limit_conn/); | |
28 | |
29 $t->write_file_expand('nginx.conf', <<'EOF'); | |
30 | |
31 %%TEST_GLOBALS%% | |
32 | |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 stream { | |
39 log_format status $status; | |
40 | |
41 limit_conn_zone $binary_remote_addr zone=zone:1m; | |
42 | |
43 server { | |
44 listen 127.0.0.1:8080; | |
45 return SEE-THIS; | |
46 access_log %%TESTDIR%%/200.log status; | |
47 } | |
48 | |
49 server { | |
50 listen 127.0.0.1:8081; | |
51 return SEE-THIS; | |
52 deny all; | |
53 access_log %%TESTDIR%%/403.log status; | |
54 } | |
55 | |
56 server { | |
57 listen 127.0.0.1:8082; | |
58 proxy_pass 127.0.0.1:8083; | |
59 access_log %%TESTDIR%%/502.log status; | |
60 | |
61 proxy_connect_timeout 0; | |
62 } | |
63 | |
64 server { | |
65 listen 127.0.0.1:8084; | |
66 proxy_bind 127.0.0.1:$remote_port; | |
67 proxy_pass 127.0.0.1:8083; | |
68 access_log %%TESTDIR%%/500.log status; | |
69 } | |
70 | |
71 server { | |
72 listen 127.0.0.1:8085; | |
73 limit_conn zone 1; | |
74 proxy_pass 127.0.0.1:8086; | |
75 access_log %%TESTDIR%%/503.log status; | |
76 | |
77 proxy_download_rate 1; | |
78 } | |
79 | |
80 server { | |
81 listen 127.0.0.1:8086; | |
82 return SEE-THIS; | |
83 } | |
84 } | |
85 | |
86 EOF | |
87 | |
88 $t->try_run('no stream access_log')->plan(5); | |
89 | |
90 ############################################################################### | |
91 | |
92 stream('127.0.0.1:' . port(8080))->read(); | |
93 stream('127.0.0.1:' . port(8081))->read(); | |
94 stream('127.0.0.1:' . port(8082))->read(); | |
95 stream('127.0.0.1:' . port(8084))->read() if $^O ne 'MSWin32'; | |
96 | |
97 my $s = stream('127.0.0.1:' . port(8085)); | |
98 $s->write('busy'); | |
99 stream('127.0.0.1:' . port(8085))->read(); | |
100 $s->read(); | |
101 undef $s; | |
102 | |
103 $t->stop(); | |
104 | |
105 is($t->read_file('200.log'), "200\n", 'stream status 200'); | |
106 is($t->read_file('403.log'), "403\n", 'stream status 403'); | |
107 | |
108 SKIP: { | |
109 skip 'win32', 1 if $^O eq 'MSWin32'; | |
110 | |
111 is($t->read_file('500.log'), "500\n", 'stream status 500'); | |
112 | |
113 } | |
114 | |
115 is($t->read_file('502.log'), "502\n", 'stream status 502'); | |
116 is($t->read_file('503.log'), "503\n200\n", 'stream status 503'); | |
117 | |
118 ############################################################################### |