Mercurial > hg > nginx-tests
annotate stream_error_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 | 38f1fd9ca3e6 |
children |
rev | line source |
---|---|
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Stream tests for error_log. |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use IO::Select; |
1600
b61e820caa83
Tests: using Sys::Hostname to get hostname in a portable way.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
16 use Sys::Hostname; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 BEGIN { use FindBin; chdir($FindBin::Bin); } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use lib 'lib'; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 use Test::Nginx; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
567
diff
changeset
|
22 use Test::Nginx::Stream qw/ stream /; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 ############################################################################### |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDERR; $| = 1; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 select STDOUT; $| = 1; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
562
abf5f3197967
Tests: skipped stream_error_log.t on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
558
diff
changeset
|
29 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
abf5f3197967
Tests: skipped stream_error_log.t on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
558
diff
changeset
|
30 |
567
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
31 my $t = Test::Nginx->new()->has(qw/stream/)->plan(34); |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 $t->write_file_expand('nginx.conf', <<'EOF'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 %%TEST_GLOBALS%% |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 error_log %%TESTDIR%%/e_glob.log info; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 error_log %%TESTDIR%%/e_glob2.log info; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1235
diff
changeset
|
39 error_log syslog:server=127.0.0.1:%%PORT_8983_UDP%% info; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 daemon off; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 events { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1600
diff
changeset
|
47 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1600
diff
changeset
|
48 |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 upstream u { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1235
diff
changeset
|
50 server 127.0.0.1:%%PORT_8983_UDP%% down; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
54 listen 127.0.0.1:8080; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 proxy_pass u; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 error_log %%TESTDIR%%/e_debug.log debug; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 error_log %%TESTDIR%%/e_info.log info; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 error_log %%TESTDIR%%/e_emerg.log emerg; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 error_log stderr info; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
64 listen 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
65 proxy_pass 127.0.0.1:8081; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 error_log %%TESTDIR%%/e_stream.log info; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1235
diff
changeset
|
68 error_log syslog:server=127.0.0.1:%%PORT_8985_UDP%% info; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1235
diff
changeset
|
69 error_log syslog:server=127.0.0.1:%%PORT_8984_UDP%% info; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 EOF |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 open OLDERR, ">&", \*STDERR; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 open STDERR, '>', $t->testdir() . '/stderr' or die "Can't reopen STDERR: $!"; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 open my $stderr, '<', $t->testdir() . '/stderr' |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 or die "Can't open stderr file: $!"; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 $t->run_daemon(\&stream_daemon); |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1235
diff
changeset
|
81 $t->run_daemon(\&syslog_daemon, port(8983), $t, 's_glob.log'); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1235
diff
changeset
|
82 $t->run_daemon(\&syslog_daemon, port(8984), $t, 's_stream.log'); |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
84 $t->waitforsocket('127.0.0.1:' . port(8081)); |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 $t->waitforfile($t->testdir . '/s_glob.log'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 $t->waitforfile($t->testdir . '/s_stream.log'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 $t->run(); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 open STDERR, ">&", \*OLDERR; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 ############################################################################### |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
1235
3fc6817cd84a
Tests: explicit peer port in stream tests now required.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
94 stream('127.0.0.1:' . port(8080))->io('data'); |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 # error_log levels |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 SKIP: { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 skip "no --with-debug", 1 unless $t->has_module('--with-debug'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 isnt(lines($t, 'e_debug.log', '[debug]'), 0, 'file debug in debug'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 isnt(lines($t, 'e_info.log', '[info]'), 0, 'file info in info'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 is(lines($t, 'e_info.log', '[debug]'), 0, 'file debug in info'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 isnt(lines($t, 'stderr', '[info]'), 0, 'stderr info in info'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 is(lines($t, 'stderr', '[debug]'), 0, 'stderr debug in info'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 # multiple error_log |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 like($t->read_file('e_glob.log'), qr!nginx/[.0-9]+!, 'error global'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 like($t->read_file('e_glob2.log'), qr!nginx/[.0-9]+!, 'error global 2'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 is_deeply(levels($t, 'e_glob.log'), levels($t, 'e_glob2.log'), |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 'multiple error global'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 # syslog |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
119 parse_syslog_message('syslog', get_syslog('data2', '127.0.0.1:' . port(8082), |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1235
diff
changeset
|
120 port(8985))); |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 is_deeply(levels($t, 's_glob.log'), levels($t, 'e_glob.log'), |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 'global syslog messages'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 is_deeply(levels($t, 's_stream.log'), levels($t, 'e_stream.log'), |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 'stream syslog messages'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 # error_log context |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 SKIP: { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 skip "relies on error log contents", 5 unless $ENV{TEST_NGINX_UNSAFE}; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 my $msg = 'no live upstreams while connecting to upstream, ' |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
133 . 'client: 127.0.0.1, server: 127.0.0.1:' . port(8080) |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
134 . ', upstream: "u"'; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 unlike($t->read_file('e_glob.log'), qr/$msg/ms, 'stream error in global'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 like($t->read_file('e_info.log'), qr/$msg/ms, 'stream error in info'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 like($t->read_file('stderr'), qr/$msg/ms, 'stream error in info stderr'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 unlike($t->read_file('e_emerg.log'), qr/$msg/ms, 'stream error in emerg'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 $msg = "bytes from/to client:5/4, bytes from/to upstream:4/5"; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 like($t->read_file('e_stream.log'), qr/$msg/ms, 'stream byte counters'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 ############################################################################### |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 sub lines { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 my ($t, $file, $pattern) = @_; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 if ($file eq 'stderr') { |
1897
38f1fd9ca3e6
Tests: unbreak reading new stderr data after eof.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1609
diff
changeset
|
153 my $value = map { $_ =~ /\Q$pattern\E/ } (<$stderr>); |
38f1fd9ca3e6
Tests: unbreak reading new stderr data after eof.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1609
diff
changeset
|
154 $stderr->clearerr(); |
38f1fd9ca3e6
Tests: unbreak reading new stderr data after eof.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1609
diff
changeset
|
155 return $value; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 my $path = $t->testdir() . '/' . $file; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 open my $fh, '<', $path or return "$!"; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 my $value = map { $_ =~ /\Q$pattern\E/ } (<$fh>); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 close $fh; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 return $value; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 sub levels { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 my ($t, $file) = @_; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 my %levels_hash; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 map { $levels_hash{$_}++; } ($t->read_file($file) =~ /(\[\w+\])/g); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 return \%levels_hash; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 |
567
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
174 sub get_syslog { |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
175 my ($data, $peer, $port) = @_; |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
176 my ($s); |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
177 |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
178 eval { |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
179 local $SIG{ALRM} = sub { die "timeout\n" }; |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
180 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
181 alarm(1); |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
182 $s = IO::Socket::INET->new( |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
183 Proto => 'udp', |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
184 LocalAddr => "127.0.0.1:$port" |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
185 ); |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
186 alarm(0); |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
187 }; |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
188 alarm(0); |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
189 if ($@) { |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
190 log_in("died: $@"); |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
191 return undef; |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
192 } |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
193 |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
567
diff
changeset
|
194 stream($peer)->io($data); |
567
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
195 $data = ''; |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
196 |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
197 IO::Select->new($s)->can_read(1.5); |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
198 while (IO::Select->new($s)->can_read(0.1)) { |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
199 my $buffer; |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
200 sysread($s, $buffer, 4096); |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
201 $data .= $buffer; |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
202 } |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
203 $s->close(); |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
204 return $data; |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
205 } |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
206 |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 sub parse_syslog_message { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 my ($desc, $line) = @_; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 |
567
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
210 ok($line, $desc); |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
211 |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
212 SKIP: { |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
213 skip "$desc timeout", 18 unless $line; |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
214 |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
215 my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
216 'Sep', 'Oct', 'Nov', 'Dec'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
217 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
218 my ($pri, $mon, $mday, $hour, $minute, $sec, $host, $tag, $msg) = |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
219 $line =~ /^<(\d{1,3})> # PRI |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
220 ([A-Z][a-z]{2})\s # mon |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
221 ([ \d]\d)\s(\d{2}):(\d{2}):(\d{2})\s # date |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
222 ([\S]*)\s # host |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
223 (\w{1,32}):\s # tag |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
224 (.*)/x; # MSG |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
225 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
226 my $sev = $pri & 0x07; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
227 my $fac = ($pri & 0x03f8) >> 3; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
228 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
229 ok(defined($pri), "$desc has PRI"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
230 ok($sev >= 0 && $sev <= 7, "$desc valid severity"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
231 ok($fac >= 0 && $fac < 24, "$desc valid facility"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
232 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
233 ok(defined($mon), "$desc has month"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
234 ok((grep $mon, @months), "$desc valid month"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
235 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
236 ok(defined($mday), "$desc has day"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
237 ok($mday <= 31, "$desc valid day"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
238 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
239 ok(defined($hour), "$desc has hour"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
240 ok($hour < 24, "$desc valid hour"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
241 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
242 ok(defined($minute), "$desc has minutes"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
243 ok($minute < 60, "$desc valid minutes"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
244 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
245 ok(defined($sec), "$desc has seconds"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
246 ok($sec < 60, "$desc valid seconds"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
247 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
248 ok(defined($host), "$desc has host"); |
1600
b61e820caa83
Tests: using Sys::Hostname to get hostname in a portable way.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
249 is($host, lc(hostname()), "$desc valid host"); |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
250 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
251 ok(defined($tag), "$desc has tag"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
252 like($tag, qr'\w+', "$desc valid tag"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
253 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
254 ok(length($msg) > 0, "$desc valid CONTENT"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
255 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
256 |
567
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
257 } |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
258 |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
259 ############################################################################### |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
260 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
261 sub syslog_daemon { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
262 my ($port, $t, $file) = @_; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
263 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
264 my $s = IO::Socket::INET->new( |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
265 Proto => 'udp', |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
266 LocalAddr => "127.0.0.1:$port" |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
267 ); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
268 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
269 open my $fh, '>', $t->testdir() . '/' . $file; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
270 select $fh; $| = 1; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
271 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
272 while (1) { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
273 my $buffer; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
274 $s->recv($buffer, 4096); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
275 print $fh $buffer . "\n"; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
276 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
277 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
278 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
279 sub stream_daemon { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
280 my $server = IO::Socket::INET->new( |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
281 Proto => 'tcp', |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
282 LocalHost => '127.0.0.1', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
283 LocalPort => port(8081), |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
284 Listen => 5, |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
285 Reuse => 1 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
286 ) |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
287 or die "Can't create listening socket: $!\n"; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
288 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
289 local $SIG{PIPE} = 'IGNORE'; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
290 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
291 while (my $client = $server->accept()) { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
292 $client->autoflush(1); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
293 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
294 log2c("(new connection $client)"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
295 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
296 $client->sysread(my $buffer, 65536) or next; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
297 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
298 log2i("$client $buffer"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
299 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
300 $buffer = $client->sockport(); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
301 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
302 log2o("$client $buffer"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
303 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
304 $client->syswrite($buffer); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
305 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
306 close $client; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
307 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
308 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
309 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
310 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
311 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
312 sub log2c { Test::Nginx::log_core('||', @_); } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
313 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
314 ############################################################################### |