Mercurial > hg > nginx-tests
annotate stub_status.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | c544b7120a6d |
children |
rev | line source |
---|---|
597
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for stub status module. |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http stub_status/)->plan(34); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 events { |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 } |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 http { |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
40 listen 127.0.0.1:8080; |
597
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 server_name localhost; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 add_header X-Active $connections_active; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 add_header X-Reading $connections_reading; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 add_header X-Writing $connections_writing; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 add_header X-Waiting $connections_waiting; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 location / { } |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 location /rate { |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 limit_rate 15; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 } |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 location /stub { |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 stub_status; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 } |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 } |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 } |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 EOF |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 $t->write_file('index.html', ''); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 $t->run(); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 ############################################################################### |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 my %status = status('/stub'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 like(http_get('/stub'), qr/200 OK/, 'get request'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 is($status{'active'}, 1, 'open connection'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 is($status{'requests'}, 1, 'first request'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 is($status{'accepts'}, 1, 'first request accepted'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 is($status{'handled'}, 1, 'first request handled'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 is($status{'writing'}, 1, 'first response'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 is($status{'reading'}, 0, 'not reading'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 # pipelined requests |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 |
600
3832869ba854
Tests: cleanup stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
599
diff
changeset
|
76 http(<<EOF); |
597
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 GET / HTTP/1.1 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 Host: localhost |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 GET / HTTP/1.1 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 Host: localhost |
599
868ff7169ec8
Tests: fixed stub_status tests, notably on freebsd.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
597
diff
changeset
|
82 Connection: close |
597
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 EOF |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 %status = status('/stub'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 is($status{'requests'}, 5, 'requests increased by 2'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 is($status{'accepts'}, 4, 'accepts increased by 1'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 # states |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
91 |
600
3832869ba854
Tests: cleanup stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
599
diff
changeset
|
92 my $s = http('', start => 1); |
597
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 %status = status('/stub'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
95 is($status{'active'}, 2, 'active'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
96 is($status{'waiting'}, 1, 'waiting state'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
97 is($status{'reading'}, 0, 'waiting state - not reading'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 is($status{'writing'}, 1, 'waiting state - not writing'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
99 |
599
868ff7169ec8
Tests: fixed stub_status tests, notably on freebsd.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
597
diff
changeset
|
100 http(<<EOF, start => 1, socket => $s, sleep => 0.2); |
597
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
101 GET /rate HTTP/1.0 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
102 EOF |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
103 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
104 %status = status('/stub'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
105 is($status{'waiting'}, 0, 'reading state - not waiting'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
106 is($status{'reading'}, 1, 'reading state'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
107 is($status{'writing'}, 1, 'reading state - not writing'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
108 |
599
868ff7169ec8
Tests: fixed stub_status tests, notably on freebsd.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
597
diff
changeset
|
109 http(<<EOF, start => 1, socket => $s, sleep => 0.2); |
597
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
110 Host: localhost |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
111 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
112 EOF |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
113 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
114 %status = status('/stub'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
115 is($status{'waiting'}, 0, 'writing state - not waiting'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
116 is($status{'reading'}, 0, 'writing state - not reading'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
117 is($status{'writing'}, 2, 'writing state'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
118 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
119 $s->close(); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
120 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
121 # head and post requests |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
122 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
123 like(http_head('/stub'), qr/200 OK/, 'head request'); |
1957
c544b7120a6d
Tests: removed dependencies on 405 error text.
Maxim Dounin <mdounin@mdounin.ru>
parents:
974
diff
changeset
|
124 like(http_post('/stub'), qr/ 405 /, 'post request'); |
597
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
125 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
126 # embedded variables in headers |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
127 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
128 my $r = http_get('/stub'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
129 like($r, qr/X-Active: 1/, 'get - var active'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
130 like($r, qr/X-Reading: 0/, 'get - var reading'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
131 like($r, qr/X-Writing: 1/, 'get - var writing'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
132 like($r, qr/X-Waiting: 0/, 'get - var waiting'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
133 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
134 $r = http_head('/stub'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
135 like($r, qr/X-Active: 1/, 'head - var active'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
136 like($r, qr/X-Reading: 0/, 'head - var reading'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
137 like($r, qr/X-Writing: 1/, 'head - var writing'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
138 like($r, qr/X-Waiting: 0/, 'head - var waiting'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
139 is(get_body($r), '', 'head - empty body'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
140 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
141 $r = http_get('/'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
142 like($r, qr/X-Active: 1/, 'no stub - var active'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
143 like($r, qr/X-Reading: 0/, 'no stub - var reading'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
144 like($r, qr/X-Writing: 1/, 'no stub - var writing'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
145 like($r, qr/X-Waiting: 0/, 'no stub - var waiting'); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
146 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
147 ############################################################################### |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
148 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
149 sub get_body { |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
150 my ($r) = @_; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
151 $r =~ /.*?\x0d\x0a?\x0d\x0a?(.*)/ms; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
152 return $1; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
153 } |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
154 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
155 sub http_post { |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
156 my ($url) = @_; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
157 return http(<<EOF); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
158 POST $url HTTP/1.0 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
159 Host: localhost |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
160 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
161 EOF |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
162 } |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
163 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
164 sub status { |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
165 my ($url) = @_; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
166 my $r = http_get($url); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
167 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
168 $r =~ / |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
169 Active\ connections:\ +(\d+) |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
170 \s+server\ accepts\ handled\ requests |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
171 \s+(\d+)\ +(\d+)\ +(\d+) |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
172 \s+Reading:\ +(\d+) |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
173 \s+Writing:\ +(\d+) |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
174 \s+Waiting:\ +(\d+) |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
175 /sx; |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
176 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
177 return ('active' => $1, |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
178 'accepts' => $2, |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
179 'handled' => $3, |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
180 'requests' => $4, |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
181 'reading' => $5, |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
182 'writing' => $6, |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
183 'waiting' => $7, |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
184 ); |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
185 } |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
186 |
66f4d8cb719e
Tests: some stub_status tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
187 ############################################################################### |