Mercurial > hg > nginx-tests
comparison debug_connection_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 | cf14cfe9ec8c |
comparison
equal
deleted
inserted
replaced
1127:6620cd57a96a | 1128:bef8be8a6224 |
---|---|
56 | 56 |
57 $t->try_run('no inet6 support')->plan(5); | 57 $t->try_run('no inet6 support')->plan(5); |
58 | 58 |
59 ############################################################################### | 59 ############################################################################### |
60 | 60 |
61 is(get_syslog('/', port(8081)), '', 'no debug_connection syslog 1'); | 61 my ($s1, $s2) = map { |
62 is(get_syslog('/', port(8082)), '', 'no debug_connection syslog 2'); | 62 IO::Socket::INET->new( |
63 Proto => 'udp', | |
64 LocalAddr => "127.0.0.1:$_" | |
65 ) | |
66 or die "Can't open syslog socket $_: $!"; | |
67 } port(8081), port(8082); | |
63 | 68 |
64 my @msgs = get_syslog('/debug', port(8081), port(8082)); | 69 is(get_syslog('/', $s1), '', 'no debug_connection syslog 1'); |
70 is(get_syslog('/', $s2), '', 'no debug_connection syslog 2'); | |
71 | |
72 my @msgs = get_syslog('/debug', $s1, $s2); | |
65 like($msgs[0], qr/\[debug\]/, 'debug_connection syslog 1'); | 73 like($msgs[0], qr/\[debug\]/, 'debug_connection syslog 1'); |
66 like($msgs[1], qr/\[debug\]/, 'debug_connection syslog 2'); | 74 like($msgs[1], qr/\[debug\]/, 'debug_connection syslog 2'); |
67 is($msgs[0], $msgs[1], 'debug_connection syslog1 syslog2 match'); | 75 is($msgs[0], $msgs[1], 'debug_connection syslog1 syslog2 match'); |
68 | 76 |
69 ############################################################################### | 77 ############################################################################### |
70 | 78 |
71 sub get_syslog { | 79 sub get_syslog { |
72 my ($uri, @port) = @_; | 80 my ($uri, @s) = @_; |
73 my (@s); | |
74 my @data; | 81 my @data; |
75 | |
76 eval { | |
77 local $SIG{ALRM} = sub { die "timeout\n" }; | |
78 local $SIG{PIPE} = sub { die "sigpipe\n" }; | |
79 alarm(1); | |
80 map { | |
81 push @s, IO::Socket::INET->new( | |
82 Proto => 'udp', | |
83 LocalAddr => "127.0.0.1:$_" | |
84 ); | |
85 } (@port); | |
86 alarm(0); | |
87 }; | |
88 alarm(0); | |
89 if ($@) { | |
90 log_in("died: $@"); | |
91 return undef; | |
92 } | |
93 | 82 |
94 http_get($uri); | 83 http_get($uri); |
95 | 84 |
96 map { | 85 map { |
97 my $data = ''; | 86 my $data = ''; |
100 my ($buffer); | 89 my ($buffer); |
101 sysread($_, $buffer, 4096); | 90 sysread($_, $buffer, 4096); |
102 $data .= $buffer; | 91 $data .= $buffer; |
103 } | 92 } |
104 push @data, $data; | 93 push @data, $data; |
105 $_->close(); | |
106 } (@s); | 94 } (@s); |
107 | 95 |
108 return $data[0] if scalar @data == 1; | 96 return $data[0] if scalar @data == 1; |
109 return @data; | 97 return @data; |
110 } | 98 } |