Mercurial > hg > nginx-tests
comparison stream_error_log.t @ 567:22bade4c7e12
Tests: in stream, made sure to get syslog data to test its format.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 30 Apr 2015 15:52:26 +0300 |
parents | ff49e1c00b35 |
children | 77359b849cd5 |
comparison
equal
deleted
inserted
replaced
566:4296379213c8 | 567:22bade4c7e12 |
---|---|
24 select STDERR; $| = 1; | 24 select STDERR; $| = 1; |
25 select STDOUT; $| = 1; | 25 select STDOUT; $| = 1; |
26 | 26 |
27 plan(skip_all => 'win32') if $^O eq 'MSWin32'; | 27 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
28 | 28 |
29 my $t = Test::Nginx->new()->has(qw/stream/)->plan(33); | 29 my $t = Test::Nginx->new()->has(qw/stream/)->plan(34); |
30 | 30 |
31 $t->write_file_expand('nginx.conf', <<'EOF'); | 31 $t->write_file_expand('nginx.conf', <<'EOF'); |
32 | 32 |
33 %%TEST_GLOBALS%% | 33 %%TEST_GLOBALS%% |
34 | 34 |
59 server { | 59 server { |
60 listen 127.0.0.1:8082; | 60 listen 127.0.0.1:8082; |
61 proxy_pass 127.0.0.1:8081; | 61 proxy_pass 127.0.0.1:8081; |
62 | 62 |
63 error_log %%TESTDIR%%/e_stream.log info; | 63 error_log %%TESTDIR%%/e_stream.log info; |
64 error_log syslog:server=127.0.0.1:8080 info; | |
64 error_log syslog:server=127.0.0.1:8084 info; | 65 error_log syslog:server=127.0.0.1:8084 info; |
65 } | 66 } |
66 } | 67 } |
67 | 68 |
68 EOF | 69 EOF |
109 is_deeply(levels($t, 'e_glob.log'), levels($t, 'e_glob2.log'), | 110 is_deeply(levels($t, 'e_glob.log'), levels($t, 'e_glob2.log'), |
110 'multiple error global'); | 111 'multiple error global'); |
111 | 112 |
112 # syslog | 113 # syslog |
113 | 114 |
114 stream_get('data2', '127.0.0.1:8082'); | 115 parse_syslog_message('syslog', get_syslog('data2', '127.0.0.1:8082')); |
115 | |
116 parse_syslog_message('syslog', $t->read_file('s_stream.log')); | |
117 | 116 |
118 is_deeply(levels($t, 's_glob.log'), levels($t, 'e_glob.log'), | 117 is_deeply(levels($t, 's_glob.log'), levels($t, 'e_glob.log'), |
119 'global syslog messages'); | 118 'global syslog messages'); |
120 is_deeply(levels($t, 's_stream.log'), levels($t, 'e_stream.log'), | 119 is_deeply(levels($t, 's_stream.log'), levels($t, 'e_stream.log'), |
121 'stream syslog messages'); | 120 'stream syslog messages'); |
218 | 217 |
219 log_in($buf); | 218 log_in($buf); |
220 return $buf; | 219 return $buf; |
221 } | 220 } |
222 | 221 |
222 sub get_syslog { | |
223 my ($data, $peer, $port) = @_; | |
224 my ($s); | |
225 my $rfd = ''; | |
226 | |
227 $port = 8080 unless defined $port; | |
228 | |
229 eval { | |
230 local $SIG{ALRM} = sub { die "timeout\n" }; | |
231 local $SIG{PIPE} = sub { die "sigpipe\n" }; | |
232 alarm(1); | |
233 $s = IO::Socket::INET->new( | |
234 Proto => 'udp', | |
235 LocalAddr => "127.0.0.1:$port" | |
236 ); | |
237 alarm(0); | |
238 }; | |
239 alarm(0); | |
240 if ($@) { | |
241 log_in("died: $@"); | |
242 return undef; | |
243 } | |
244 | |
245 stream_get($data, $peer); | |
246 $data = ''; | |
247 | |
248 IO::Select->new($s)->can_read(1.5); | |
249 while (IO::Select->new($s)->can_read(0.1)) { | |
250 my $buffer; | |
251 sysread($s, $buffer, 4096); | |
252 $data .= $buffer; | |
253 } | |
254 $s->close(); | |
255 return $data; | |
256 } | |
257 | |
223 sub parse_syslog_message { | 258 sub parse_syslog_message { |
224 my ($desc, $line) = @_; | 259 my ($desc, $line) = @_; |
260 | |
261 ok($line, $desc); | |
262 | |
263 SKIP: { | |
264 skip "$desc timeout", 18 unless $line; | |
225 | 265 |
226 my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', | 266 my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', |
227 'Sep', 'Oct', 'Nov', 'Dec'); | 267 'Sep', 'Oct', 'Nov', 'Dec'); |
228 | 268 |
229 my ($pri, $mon, $mday, $hour, $minute, $sec, $host, $tag, $msg) = | 269 my ($pri, $mon, $mday, $hour, $minute, $sec, $host, $tag, $msg) = |
262 | 302 |
263 ok(defined($tag), "$desc has tag"); | 303 ok(defined($tag), "$desc has tag"); |
264 like($tag, qr'\w+', "$desc valid tag"); | 304 like($tag, qr'\w+', "$desc valid tag"); |
265 | 305 |
266 ok(length($msg) > 0, "$desc valid CONTENT"); | 306 ok(length($msg) > 0, "$desc valid CONTENT"); |
307 } | |
308 | |
267 } | 309 } |
268 | 310 |
269 ############################################################################### | 311 ############################################################################### |
270 | 312 |
271 sub syslog_daemon { | 313 sub syslog_daemon { |