comparison syslog.t @ 952:e9064d691790

Tests: converted tests to run in parallel.
author Andrey Zelenkov <zelenkov@nginx.com>
date Tue, 21 Jun 2016 16:39:13 +0300
parents bc9e519ab3bc
children 882267679006
comparison
equal deleted inserted replaced
951:9361c7eddfc1 952:e9064d691790
28 28
29 $t->write_file_expand('nginx.conf', <<'EOF'); 29 $t->write_file_expand('nginx.conf', <<'EOF');
30 30
31 %%TEST_GLOBALS%% 31 %%TEST_GLOBALS%%
32 32
33 error_log syslog:server=127.0.0.1:8083 info; 33 error_log syslog:server=127.0.0.1:%%PORT_1_UDP%% info;
34 error_log %%TESTDIR%%/f_glob.log info; 34 error_log %%TESTDIR%%/f_glob.log info;
35 35
36 daemon off; 36 daemon off;
37 37
38 events { 38 events {
44 limit_req_zone $binary_remote_addr zone=one:1m rate=1r/m; 44 limit_req_zone $binary_remote_addr zone=one:1m rate=1r/m;
45 45
46 log_format empty ""; 46 log_format empty "";
47 log_format logf "$uri:$status"; 47 log_format logf "$uri:$status";
48 48
49 error_log syslog:server=127.0.0.1:8084 info; 49 error_log syslog:server=127.0.0.1:%%PORT_2_UDP%% info;
50 error_log %%TESTDIR%%/f_http.log info; 50 error_log %%TESTDIR%%/f_http.log info;
51 51
52 server { 52 server {
53 listen 127.0.0.1:8080; 53 listen 127.0.0.1:%%PORT_0%%;
54 server_name localhost; 54 server_name localhost;
55 55
56 location /e { 56 location /e {
57 error_log syslog:server=127.0.0.1:8080; 57 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
58 } 58 }
59 location /a { 59 location /a {
60 access_log syslog:server=127.0.0.1:8080; 60 access_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
61 } 61 }
62 location /ef { 62 location /ef {
63 error_log syslog:server=127.0.0.1:8080,facility=user; 63 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%,facility=user;
64 } 64 }
65 location /es { 65 location /es {
66 error_log syslog:server=127.0.0.1:8080,severity=alert; 66 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%,severity=alert;
67 } 67 }
68 location /et { 68 location /et {
69 error_log syslog:server=127.0.0.1:8080,tag=SEETHIS; 69 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%,tag=SEETHIS;
70 } 70 }
71 location /af { 71 location /af {
72 access_log syslog:server=127.0.0.1:8080,facility=user; 72 access_log syslog:server=127.0.0.1:%%PORT_4_UDP%%,facility=user;
73 } 73 }
74 location /as { 74 location /as {
75 # put severity inside to catch possible parsing programming errors 75 # put severity inside to catch possible parsing programming errors
76 access_log syslog:severity=alert,server=127.0.0.1:8080; 76 access_log syslog:severity=alert,server=127.0.0.1:%%PORT_4_UDP%%;
77 } 77 }
78 location /at { 78 location /at {
79 access_log syslog:server=127.0.0.1:8080,tag=SEETHIS; 79 access_log syslog:server=127.0.0.1:%%PORT_4_UDP%%,tag=SEETHIS;
80 } 80 }
81 location /e2 { 81 location /e2 {
82 error_log syslog:server=127.0.0.1:8080; 82 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
83 error_log syslog:server=127.0.0.1:8080; 83 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
84 } 84 }
85 location /a2 { 85 location /a2 {
86 access_log syslog:server=127.0.0.1:8080; 86 access_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
87 access_log syslog:server=127.0.0.1:8080; 87 access_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
88 } 88 }
89 location /a_logf { 89 location /a_logf {
90 access_log syslog:server=127.0.0.1:8080 logf; 90 access_log syslog:server=127.0.0.1:%%PORT_4_UDP%% logf;
91 } 91 }
92 location /if { 92 location /if {
93 access_log syslog:server=127.0.0.1:8085 logf if=$arg_logme; 93 access_log syslog:server=127.0.0.1:%%PORT_3_UDP%% logf
94 if=$arg_logme;
94 } 95 }
95 96
96 location /nohostname { 97 location /nohostname {
97 access_log syslog:server=127.0.0.1:8080,nohostname; 98 access_log syslog:server=127.0.0.1:%%PORT_4_UDP%%,nohostname;
98 } 99 }
99 100
100 location /debug { 101 location /debug {
101 limit_req zone=one; 102 limit_req zone=one;
102 error_log syslog:server=127.0.0.1:8080 debug; 103 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%% debug;
103 } 104 }
104 location /info { 105 location /info {
105 limit_req zone=one; 106 limit_req zone=one;
106 limit_req_log_level info; 107 limit_req_log_level info;
107 error_log syslog:server=127.0.0.1:8080 info; 108 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%% info;
108 } 109 }
109 location /notice { 110 location /notice {
110 limit_req zone=one; 111 limit_req zone=one;
111 limit_req_log_level notice; 112 limit_req_log_level notice;
112 error_log syslog:server=127.0.0.1:8080 notice; 113 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%% notice;
113 } 114 }
114 location /warn { 115 location /warn {
115 limit_req zone=one; 116 limit_req zone=one;
116 limit_req_log_level warn; 117 limit_req_log_level warn;
117 error_log syslog:server=127.0.0.1:8080 warn; 118 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%% warn;
118 } 119 }
119 location /error { 120 location /error {
120 limit_req zone=one; 121 limit_req zone=one;
121 limit_req_log_level error; 122 limit_req_log_level error;
122 error_log syslog:server=127.0.0.1:8080; 123 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
123 } 124 }
124 location /low { 125 location /low {
125 error_log syslog:server=127.0.0.1:8080 warn; 126 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%% warn;
126 error_log syslog:server=127.0.0.1:8080; 127 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
127 } 128 }
128 location /dup { 129 location /dup {
129 error_log syslog:server=127.0.0.1:8080; 130 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
130 error_log syslog:server=127.0.0.1:8080; 131 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
131 } 132 }
132 location /high { 133 location /high {
133 error_log syslog:server=127.0.0.1:8080 emerg; 134 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%% emerg;
134 error_log syslog:server=127.0.0.1:8080; 135 error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
135 } 136 }
136 } 137 }
137 } 138 }
138 139
139 EOF 140 EOF
140 141
141 $t->run_daemon(\&syslog_daemon, 8083, $t, 's_glob.log'); 142 $t->run_daemon(\&syslog_daemon, port(1), $t, 's_glob.log');
142 $t->run_daemon(\&syslog_daemon, 8084, $t, 's_http.log'); 143 $t->run_daemon(\&syslog_daemon, port(2), $t, 's_http.log');
143 $t->run_daemon(\&syslog_daemon, 8085, $t, 's_if.log'); 144 $t->run_daemon(\&syslog_daemon, port(3), $t, 's_if.log');
144 145
145 $t->waitforfile($t->testdir . '/s_glob.log'); 146 $t->waitforfile($t->testdir . '/s_glob.log');
146 $t->waitforfile($t->testdir . '/s_http.log'); 147 $t->waitforfile($t->testdir . '/s_http.log');
147 $t->waitforfile($t->testdir . '/s_if.log'); 148 $t->waitforfile($t->testdir . '/s_if.log');
148 149
224 225
225 ############################################################################### 226 ###############################################################################
226 227
227 sub syslog_lines { 228 sub syslog_lines {
228 my ($uri, $pattern, $port) = @_; 229 my ($uri, $pattern, $port) = @_;
229 return map { $_ =~ /\Q$pattern\E/g } (get_syslog($uri, $port)); 230 return map { $_ =~ /\Q$pattern\E/g } (get_syslog($uri));
230 } 231 }
231 232
232 sub levels { 233 sub levels {
233 my ($t, $file) = @_; 234 my ($t, $file) = @_;
234 my %levels_hash; 235 my %levels_hash;
237 238
238 return \%levels_hash; 239 return \%levels_hash;
239 } 240 }
240 241
241 sub get_syslog { 242 sub get_syslog {
242 my ($uri, $port) = @_; 243 my ($uri) = @_;
243 my ($s); 244 my ($s);
244 my $rfd = ''; 245 my $rfd = '';
245 my $data = ''; 246 my $data = '';
246
247 $port = 8080 unless defined $port;
248 247
249 eval { 248 eval {
250 local $SIG{ALRM} = sub { die "timeout\n" }; 249 local $SIG{ALRM} = sub { die "timeout\n" };
251 local $SIG{PIPE} = sub { die "sigpipe\n" }; 250 local $SIG{PIPE} = sub { die "sigpipe\n" };
252 alarm(1); 251 alarm(1);
253 $s = IO::Socket::INET->new( 252 $s = IO::Socket::INET->new(
254 Proto => 'udp', 253 Proto => 'udp',
255 LocalAddr => "127.0.0.1:$port" 254 LocalAddr => '127.0.0.1:' . port(4)
256 ); 255 );
257 alarm(0); 256 alarm(0);
258 }; 257 };
259 alarm(0); 258 alarm(0);
260 if ($@) { 259 if ($@) {