Mercurial > hg > nginx-tests
annotate stream_access_log.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 |
---|---|
1024
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream access_log module and variables. |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
1600
b61e820caa83
Tests: using Sys::Hostname to get hostname in a portable way.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1485
diff
changeset
|
15 use Sys::Hostname; |
b61e820caa83
Tests: using Sys::Hostname to get hostname in a portable way.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1485
diff
changeset
|
16 |
1024
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 use Test::Nginx::Stream qw/ stream /; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 ############################################################################### |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
1175
717030fd5a94
Tests: added gzip prerequisite for "access_log ... gzip".
Maxim Dounin <mdounin@mdounin.ru>
parents:
1024
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/stream stream_map gzip/); |
1024
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 $t->write_file_expand('nginx.conf', <<'EOF'); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 events { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1600
diff
changeset
|
40 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1600
diff
changeset
|
41 |
1024
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 log_format test $server_addr; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 log_format vars $connection:$nginx_version:$hostname:$pid; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 log_format addr $binary_remote_addr:$remote_addr:$remote_port: |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 $server_addr:$server_port:$upstream_addr; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 log_format date $msec!$time_local!$time_iso8601; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 log_format byte $bytes_received:$bytes_sent: |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 $upstream_bytes_sent:$upstream_bytes_received; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 log_format time $upstream_connect_time:$upstream_first_byte_time: |
1485
48c3964a10a5
Tests: added stream $session_time test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
50 $upstream_session_time:$session_time; |
1024
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 access_log %%TESTDIR%%/off.log test; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 map $server_port $logme { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 %%PORT_8083%% 1; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 default 0; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 server { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 listen 127.0.0.1:8081; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 proxy_pass 127.0.0.1:8080; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 access_log off; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 server { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 listen 127.0.0.1:8082; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 proxy_pass 127.0.0.1:8080; |
1485
48c3964a10a5
Tests: added stream $session_time test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
68 proxy_download_rate 2; |
1024
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 access_log %%TESTDIR%%/time.log time; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 server { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 listen 127.0.0.1:8083; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 listen 127.0.0.1:8084; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 proxy_pass 127.0.0.1:8080; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 access_log %%TESTDIR%%/filtered.log test if=$logme; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 server { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 listen 127.0.0.1:8085; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 proxy_pass 127.0.0.1:8080; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 access_log %%TESTDIR%%/complex.log test if=$logme$logme; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 server { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 listen 127.0.0.1:8086; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 proxy_pass 127.0.0.1:8080; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 access_log %%TESTDIR%%/compressed.log test |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 gzip buffer=1m flush=100ms; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 server { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 listen 127.0.0.1:8087; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 proxy_pass 127.0.0.1:8080; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 access_log %%TESTDIR%%/varlog_$bytes_sent.log test; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 server { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 listen 127.0.0.1:8088; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 proxy_pass 127.0.0.1:8080; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 access_log %%TESTDIR%%/vars.log vars; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 access_log %%TESTDIR%%/addr.log addr; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 access_log %%TESTDIR%%/date.log date; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 access_log %%TESTDIR%%/byte.log byte; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 EOF |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 $t->run_daemon(\&stream_daemon); |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1175
diff
changeset
|
111 $t->run()->plan(10); |
1024
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 $t->waitforsocket('127.0.0.1:' . port(8080)); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 ############################################################################### |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 my $str = 'SEE-THIS'; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 stream('127.0.0.1:' . port(8081))->io($str); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 stream('127.0.0.1:' . port(8082))->io($str); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 stream('127.0.0.1:' . port(8083))->io($str); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 stream('127.0.0.1:' . port(8084))->io($str); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 stream('127.0.0.1:' . port(8085))->io($str); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 stream('127.0.0.1:' . port(8086))->io($str); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 stream('127.0.0.1:' . port(8087))->io($str); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 my $dport = port(8088); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 my $s = stream("127.0.0.1:$dport"); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 my $lhost = $s->sockhost(); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 my $escaped = $s->sockaddr(); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 $escaped =~ s/([^\x20-\x7e])/sprintf('\\x%02X', ord($1))/gmxe; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 my $lport = $s->sockport(); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 my $uport = port(8080); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 $s->io($str); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 # wait for file to appear with nonzero size thanks to the flush parameter |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 for (1 .. 10) { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 last if -s $t->testdir() . '/compressed.log'; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 select undef, undef, undef, 0.1; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 # verify that "gzip" parameter turns on compression |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 SKIP: { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 eval { require IO::Uncompress::Gunzip; }; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 skip("IO::Uncompress::Gunzip not installed", 1) if $@; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 my $gzipped = $t->read_file('compressed.log'); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 my $log; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 IO::Uncompress::Gunzip::gunzip(\$gzipped => \$log); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 like($log, qr/^127.0.0.1/, 'compressed log - flush time'); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 # now verify all other logs |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 $t->stop(); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 is($t->read_file('off.log'), '', 'log off'); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 is($t->read_file('filtered.log'), "127.0.0.1\n", 'log filtering'); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 ok($t->read_file('complex.log'), 'if with complex value'); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 ok($t->read_file('varlog_3.log'), 'variable in file'); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
1600
b61e820caa83
Tests: using Sys::Hostname to get hostname in a portable way.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1485
diff
changeset
|
165 my $hostname = lc hostname(); |
1024
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 like($t->read_file('vars.log'), qr/^\d+:[\d.]+:$hostname:\d+$/, 'log vars'); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 is($t->read_file('addr.log'), |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 "$escaped:$lhost:$lport:127.0.0.1:$dport:127.0.0.1:$uport\n", |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 'log addr'); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 like($t->read_file('date.log'), qr#^\d+.\d+![-+\w/: ]+![-+\dT:]+$#, 'log date'); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 is($t->read_file('byte.log'), "8:3:8:3\n", 'log bytes'); |
1485
48c3964a10a5
Tests: added stream $session_time test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
172 like($t->read_file('time.log'), qr/0\.\d+:0\.\d+:1\.\d+:1\.\d+/, 'log time'); |
1024
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 ############################################################################### |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 sub stream_daemon { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 my $server = IO::Socket::INET->new( |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 Proto => 'tcp', |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 LocalAddr => '127.0.0.1', |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 LocalPort => port(8080), |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 Listen => 5, |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 Reuse => 1 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 ) |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 or die "Can't create listening socket: $!\n"; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 local $SIG{PIPE} = 'IGNORE'; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 while (my $client = $server->accept()) { |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 $client->autoflush(1); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 log2c("(new connection $client)"); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 $client->sysread(my $buffer, 65536) or next; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 log2i("$client $buffer"); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 $buffer = "ack"; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 log2o("$client $buffer"); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 $client->syswrite($buffer); |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 close $client; |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 sub log2c { Test::Nginx::log_core('||', @_); } |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 |
91e64c1ceec9
Tests: stream access_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 ############################################################################### |