Mercurial > hg > nginx-tests
comparison syslog.t @ 1128:bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 10 Feb 2017 13:55:39 +0300 |
parents | 6620cd57a96a |
children | e4974af3fb12 |
comparison
equal
deleted
inserted
replaced
1127:6620cd57a96a | 1128:bef8be8a6224 |
---|---|
150 $t->waitforfile($t->testdir . '/s_if.log'); | 150 $t->waitforfile($t->testdir . '/s_if.log'); |
151 | 151 |
152 $t->run(); | 152 $t->run(); |
153 | 153 |
154 ############################################################################### | 154 ############################################################################### |
155 | |
156 my $s = IO::Socket::INET->new( | |
157 Proto => 'udp', | |
158 LocalAddr => '127.0.0.1:' . port(8084) | |
159 ) | |
160 or die "Can't open syslog socket: $!"; | |
155 | 161 |
156 parse_syslog_message('error_log', get_syslog('/e')); | 162 parse_syslog_message('error_log', get_syslog('/e')); |
157 parse_syslog_message('access_log', get_syslog('/a')); | 163 parse_syslog_message('access_log', get_syslog('/a')); |
158 | 164 |
159 like(get_syslog('/ef'), qr/^<11>/, 'error_log facility'); | 165 like(get_syslog('/ef'), qr/^<11>/, 'error_log facility'); |
241 return \%levels_hash; | 247 return \%levels_hash; |
242 } | 248 } |
243 | 249 |
244 sub get_syslog { | 250 sub get_syslog { |
245 my ($uri) = @_; | 251 my ($uri) = @_; |
246 my ($s); | |
247 my $data = ''; | 252 my $data = ''; |
248 | |
249 eval { | |
250 local $SIG{ALRM} = sub { die "timeout\n" }; | |
251 local $SIG{PIPE} = sub { die "sigpipe\n" }; | |
252 alarm(1); | |
253 $s = IO::Socket::INET->new( | |
254 Proto => 'udp', | |
255 LocalAddr => '127.0.0.1:' . port(8084) | |
256 ); | |
257 alarm(0); | |
258 }; | |
259 alarm(0); | |
260 if ($@) { | |
261 log_in("died: $@"); | |
262 return undef; | |
263 } | |
264 | 253 |
265 http_get($uri); | 254 http_get($uri); |
266 | 255 |
267 IO::Select->new($s)->can_read(1); | 256 IO::Select->new($s)->can_read(1); |
268 while (IO::Select->new($s)->can_read(0.1)) { | 257 while (IO::Select->new($s)->can_read(0.1)) { |
269 my $buffer; | 258 my $buffer; |
270 sysread($s, $buffer, 4096); | 259 sysread($s, $buffer, 4096); |
271 $data .= $buffer; | 260 $data .= $buffer; |
272 } | 261 } |
273 $s->close(); | |
274 return $data; | 262 return $data; |
275 } | 263 } |
276 | 264 |
277 sub parse_syslog_message { | 265 sub parse_syslog_message { |
278 my ($desc, $line) = @_; | 266 my ($desc, $line) = @_; |