Mercurial > hg > nginx-tests
annotate debug_connection_syslog.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | e4974af3fb12 |
children |
rev | line source |
---|---|
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Nginx, Inc. |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 # Tests for debug_connection with syslog. |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 ############################################################################### |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 use warnings; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use strict; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 use Test::More; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 |
1127
6620cd57a96a
Tests: replaced all occurrences of vec/select API with IO::Select.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1046
diff
changeset
|
14 use IO::Select; |
6620cd57a96a
Tests: replaced all occurrences of vec/select API with IO::Select.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1046
diff
changeset
|
15 |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use lib 'lib'; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
1170
cf14cfe9ec8c
Tests: dropped obsolete ipv6 prerequisite.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1128
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http --with-debug proxy/); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 events { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 debug_connection ::1; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 http { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1190
diff
changeset
|
41 error_log syslog:server=127.0.0.1:%%PORT_8981_UDP%% alert; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1190
diff
changeset
|
42 error_log syslog:server=127.0.0.1:%%PORT_8982_UDP%% alert; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 listen 127.0.0.1:8080; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
46 listen [::1]:%%PORT_8080%%; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 server_name localhost; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 location /debug { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
50 proxy_pass http://[::1]:%%PORT_8080%%/; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 EOF |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
1190
fcd65708672d
Tests: let tests pass on travis-ci VMs with disabled IPv6 loopback.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1171
diff
changeset
|
57 $t->try_run('no inet6 support')->plan(5); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 ############################################################################### |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
1128
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
61 my ($s1, $s2) = map { |
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
62 IO::Socket::INET->new( |
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
63 Proto => 'udp', |
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
64 LocalAddr => "127.0.0.1:$_" |
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
65 ) |
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
66 or die "Can't open syslog socket $_: $!"; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1190
diff
changeset
|
67 } port(8981), port(8982); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
1128
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
69 is(get_syslog('/', $s1), '', 'no debug_connection syslog 1'); |
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
70 is(get_syslog('/', $s2), '', 'no debug_connection syslog 2'); |
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
71 |
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
72 my @msgs = get_syslog('/debug', $s1, $s2); |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 like($msgs[0], qr/\[debug\]/, 'debug_connection syslog 1'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 like($msgs[1], qr/\[debug\]/, 'debug_connection syslog 2'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 is($msgs[0], $msgs[1], 'debug_connection syslog1 syslog2 match'); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 ############################################################################### |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 sub get_syslog { |
1128
bef8be8a6224
Tests: avoid reopening a receiving UDP socket in syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1127
diff
changeset
|
80 my ($uri, @s) = @_; |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 my @data; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 http_get($uri); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 map { |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 my $data = ''; |
1127
6620cd57a96a
Tests: replaced all occurrences of vec/select API with IO::Select.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1046
diff
changeset
|
87 IO::Select->new($_)->can_read(1); |
6620cd57a96a
Tests: replaced all occurrences of vec/select API with IO::Select.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1046
diff
changeset
|
88 while (IO::Select->new($_)->can_read(0.1)) { |
404
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 my ($buffer); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 sysread($_, $buffer, 4096); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 $data .= $buffer; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 push @data, $data; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 } (@s); |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 return $data[0] if scalar @data == 1; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 return @data; |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 } |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 |
997f5fe16545
Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 ############################################################################### |