Mercurial > hg > nginx-tests
annotate stream_error_log.t @ 1025:94f8cd9b41dc
Tests: stream $status tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 05 Sep 2016 22:57:44 +0300 |
parents | 882267679006 |
children | 3fc6817cd84a |
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; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
567
diff
changeset
|
21 use Test::Nginx::Stream qw/ stream /; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
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 select STDERR; $| = 1; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
562
abf5f3197967
Tests: skipped stream_error_log.t on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
558
diff
changeset
|
28 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
|
29 |
567
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
30 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
|
31 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 $t->write_file_expand('nginx.conf', <<'EOF'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 %%TEST_GLOBALS%% |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 error_log %%TESTDIR%%/e_glob.log info; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 error_log %%TESTDIR%%/e_glob2.log info; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
38 error_log syslog:server=127.0.0.1:%%PORT_8083_UDP%% info; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 daemon off; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 events { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 } |
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 stream { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 upstream u { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
47 server 127.0.0.1:%%PORT_8083_UDP%% down; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
51 listen 127.0.0.1:8080; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 proxy_pass u; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 error_log %%TESTDIR%%/e_debug.log debug; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 error_log %%TESTDIR%%/e_info.log info; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 error_log %%TESTDIR%%/e_emerg.log emerg; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 error_log stderr info; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
61 listen 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
62 proxy_pass 127.0.0.1:8081; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 error_log %%TESTDIR%%/e_stream.log info; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
65 error_log syslog:server=127.0.0.1:%%PORT_8085_UDP%% info; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
66 error_log syslog:server=127.0.0.1:%%PORT_8084_UDP%% info; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 EOF |
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 open OLDERR, ">&", \*STDERR; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 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
|
74 open my $stderr, '<', $t->testdir() . '/stderr' |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 or die "Can't open stderr file: $!"; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 $t->run_daemon(\&stream_daemon); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
78 $t->run_daemon(\&syslog_daemon, port(8083), $t, 's_glob.log'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
79 $t->run_daemon(\&syslog_daemon, port(8084), $t, 's_stream.log'); |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
81 $t->waitforsocket('127.0.0.1:' . port(8081)); |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 $t->waitforfile($t->testdir . '/s_glob.log'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 $t->waitforfile($t->testdir . '/s_stream.log'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 $t->run(); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 open STDERR, ">&", \*OLDERR; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
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 |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
567
diff
changeset
|
91 stream()->io('data'); |
558
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 # error_log levels |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 SKIP: { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 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
|
97 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 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
|
99 |
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 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 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
|
103 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
|
104 isnt(lines($t, 'stderr', '[info]'), 0, 'stderr info in info'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 is(lines($t, 'stderr', '[debug]'), 0, 'stderr debug in info'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 # multiple error_log |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 'multiple error global'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 # syslog |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
116 parse_syslog_message('syslog', get_syslog('data2', '127.0.0.1:' . port(8082), |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
117 port(8085))); |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 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
|
120 'global syslog messages'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 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
|
122 'stream syslog messages'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 # error_log context |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 SKIP: { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 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
|
128 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 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
|
130 . '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
|
131 . ', upstream: "u"'; |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 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
|
137 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 $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
|
139 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 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
|
141 |
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 |
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 sub lines { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 my ($t, $file, $pattern) = @_; |
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 if ($file eq 'stderr') { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 return map { $_ =~ /\Q$pattern\E/ } (<$stderr>); |
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 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 my $path = $t->testdir() . '/' . $file; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 open my $fh, '<', $path or return "$!"; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 my $value = map { $_ =~ /\Q$pattern\E/ } (<$fh>); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 close $fh; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 return $value; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 sub levels { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 my ($t, $file) = @_; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 my %levels_hash; |
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 map { $levels_hash{$_}++; } ($t->read_file($file) =~ /(\[\w+\])/g); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 return \%levels_hash; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 |
567
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
169 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
|
170 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
|
171 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
|
172 |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
173 eval { |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
174 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
|
175 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
|
176 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
|
177 $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
|
178 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
|
179 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
|
180 ); |
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(0); |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
182 }; |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
183 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
|
184 if ($@) { |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
185 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
|
186 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
|
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 |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
567
diff
changeset
|
189 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
|
190 $data = ''; |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
191 |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 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
|
196 $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
|
197 } |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
198 $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
|
199 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
|
200 } |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
201 |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 sub parse_syslog_message { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 my ($desc, $line) = @_; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 |
567
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
205 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
|
206 |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
207 SKIP: { |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
208 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
|
209 |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 'Sep', 'Oct', 'Nov', 'Dec'); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 my ($pri, $mon, $mday, $hour, $minute, $sec, $host, $tag, $msg) = |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
214 $line =~ /^<(\d{1,3})> # PRI |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
215 ([A-Z][a-z]{2})\s # mon |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
216 ([ \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
|
217 ([\S]*)\s # host |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
218 (\w{1,32}):\s # tag |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
219 (.*)/x; # MSG |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
220 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
221 my $sev = $pri & 0x07; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
222 my $fac = ($pri & 0x03f8) >> 3; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
223 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
224 ok(defined($pri), "$desc has PRI"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
225 ok($sev >= 0 && $sev <= 7, "$desc valid severity"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
226 ok($fac >= 0 && $fac < 24, "$desc valid facility"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
227 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
228 ok(defined($mon), "$desc has month"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
229 ok((grep $mon, @months), "$desc valid month"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
230 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
231 ok(defined($mday), "$desc has day"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
232 ok($mday <= 31, "$desc valid day"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
233 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
234 ok(defined($hour), "$desc has hour"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
235 ok($hour < 24, "$desc valid hour"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
236 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
237 ok(defined($minute), "$desc has minutes"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
238 ok($minute < 60, "$desc valid minutes"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
239 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
240 ok(defined($sec), "$desc has seconds"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
241 ok($sec < 60, "$desc valid seconds"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
242 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
243 ok(defined($host), "$desc has host"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
244 chomp(my $hostname = lc `hostname`); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
245 is($host , $hostname, "$desc valid host"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
246 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
247 ok(defined($tag), "$desc has tag"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
248 like($tag, qr'\w+', "$desc valid tag"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
249 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
250 ok(length($msg) > 0, "$desc valid CONTENT"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
251 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
252 |
567
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
253 } |
22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
254 |
558
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 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
257 sub syslog_daemon { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
258 my ($port, $t, $file) = @_; |
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 my $s = IO::Socket::INET->new( |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
261 Proto => 'udp', |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
262 LocalAddr => "127.0.0.1:$port" |
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 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
265 open my $fh, '>', $t->testdir() . '/' . $file; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
266 select $fh; $| = 1; |
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 while (1) { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
269 my $buffer; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
270 $s->recv($buffer, 4096); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
271 print $fh $buffer . "\n"; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
272 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
273 } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
274 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
275 sub stream_daemon { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
276 my $server = IO::Socket::INET->new( |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
277 Proto => 'tcp', |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
278 LocalHost => '127.0.0.1', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
279 LocalPort => port(8081), |
558
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
280 Listen => 5, |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
281 Reuse => 1 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
282 ) |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
283 or die "Can't create listening socket: $!\n"; |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
284 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
285 local $SIG{PIPE} = 'IGNORE'; |
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 while (my $client = $server->accept()) { |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
288 $client->autoflush(1); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
289 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
290 log2c("(new connection $client)"); |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
291 |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
292 $client->sysread(my $buffer, 65536) or next; |
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 log2i("$client $buffer"); |
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 $buffer = $client->sockport(); |
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 log2o("$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 $client->syswrite($buffer); |
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 close $client; |
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 } |
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 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
307 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
27740a2dd781
Tests: stream error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
308 sub log2c { Test::Nginx::log_core('||', @_); } |
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 ############################################################################### |