comparison debug_connection_syslog.t @ 404:997f5fe16545

Tests: added syslog tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 21 May 2014 17:43:42 +0400
parents
children 907e89fba9c3
comparison
equal deleted inserted replaced
403:22f6aa0d1139 404:997f5fe16545
1 #!/usr/bin/perl
2
3 # (C) Nginx, Inc.
4
5 # Tests for debug_connection with syslog.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
15
16 use lib 'lib';
17 use Test::Nginx;
18
19 ###############################################################################
20
21 select STDERR; $| = 1;
22 select STDOUT; $| = 1;
23
24 my $t = Test::Nginx->new()->has(qw/http --with-debug ipv6 proxy/);
25
26 plan(skip_all => 'no syslog') unless $t->has_version('1.7.1');
27
28 $t->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 daemon off;
33
34 events {
35 debug_connection ::1;
36 }
37
38 http {
39 %%TEST_GLOBALS_HTTP%%
40
41 error_log syslog:server=127.0.0.1:8080 alert;
42 error_log syslog:server=127.0.0.1:8081 alert;
43
44 server {
45 listen 127.0.0.1:8080;
46 listen [::1]:8080;
47 server_name localhost;
48
49 location /debug {
50 proxy_pass http://[::1]:8080/;
51 }
52 }
53 }
54
55 EOF
56
57 eval {
58 open OLDERR, ">&", \*STDERR; close STDERR;
59 $t->run();
60 open STDERR, ">&", \*OLDERR;
61 };
62 plan(skip_all => 'no inet6 support') if $@;
63
64 $t->plan(5);
65
66 ###############################################################################
67
68 is(get_syslog('/', 8080), '', 'no debug_connection syslog 1');
69 is(get_syslog('/', 8081), '', 'no debug_connection syslog 2');
70
71 my @msgs = get_syslog('/debug', 8080, 8081);
72 like($msgs[0], qr/\[debug\]/, 'debug_connection syslog 1');
73 like($msgs[1], qr/\[debug\]/, 'debug_connection syslog 2');
74 is($msgs[0], $msgs[1], 'debug_connection syslog1 syslog2 match');
75
76 ###############################################################################
77
78 sub get_syslog {
79 my ($uri, @port) = @_;
80 my (@s);
81 my $rfd = '';
82 my @data;
83
84 eval {
85 local $SIG{ALRM} = sub { die "timeout\n" };
86 local $SIG{PIPE} = sub { die "sigpipe\n" };
87 alarm(1);
88 map {
89 push @s, IO::Socket::INET->new(
90 Proto => 'udp',
91 LocalAddr => "127.0.0.1:$_"
92 );
93 } (@port);
94 alarm(0);
95 };
96 alarm(0);
97 if ($@) {
98 log_in("died: $@");
99 return undef;
100 }
101
102 http_get($uri);
103
104 map {
105 my $data = '';
106 vec($rfd, fileno($_), 1) = 1;
107 select $rfd, undef, undef, 1;
108 while (select($rfd, undef, undef, 0.1) > 0
109 && vec($rfd, fileno($_), 1))
110 {
111 my ($buffer);
112 sysread($_, $buffer, 4096);
113 $data .= $buffer;
114 }
115 push @data, $data;
116 $_->close();
117 } (@s);
118
119 return $data[0] if scalar @data == 1;
120 return @data;
121 }
122
123 ###############################################################################