diff 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
line wrap: on
line diff
--- a/syslog.t
+++ b/syslog.t
@@ -30,7 +30,7 @@ my $t = Test::Nginx->new()->has(qw/http 
 
 %%TEST_GLOBALS%%
 
-error_log syslog:server=127.0.0.1:8083 info;
+error_log syslog:server=127.0.0.1:%%PORT_1_UDP%% info;
 error_log %%TESTDIR%%/f_glob.log info;
 
 daemon off;
@@ -46,101 +46,102 @@ http {
     log_format empty "";
     log_format logf "$uri:$status";
 
-    error_log syslog:server=127.0.0.1:8084 info;
+    error_log syslog:server=127.0.0.1:%%PORT_2_UDP%% info;
     error_log %%TESTDIR%%/f_http.log info;
 
     server {
-        listen       127.0.0.1:8080;
+        listen       127.0.0.1:%%PORT_0%%;
         server_name  localhost;
 
         location /e {
-            error_log syslog:server=127.0.0.1:8080;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
         }
         location /a {
-            access_log syslog:server=127.0.0.1:8080;
+            access_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
         }
         location /ef {
-            error_log syslog:server=127.0.0.1:8080,facility=user;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%,facility=user;
         }
         location /es {
-            error_log syslog:server=127.0.0.1:8080,severity=alert;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%,severity=alert;
         }
         location /et {
-            error_log syslog:server=127.0.0.1:8080,tag=SEETHIS;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%,tag=SEETHIS;
         }
         location /af {
-            access_log syslog:server=127.0.0.1:8080,facility=user;
+            access_log syslog:server=127.0.0.1:%%PORT_4_UDP%%,facility=user;
         }
         location /as {
             # put severity inside to catch possible parsing programming errors
-            access_log syslog:severity=alert,server=127.0.0.1:8080;
+            access_log syslog:severity=alert,server=127.0.0.1:%%PORT_4_UDP%%;
         }
         location /at {
-            access_log syslog:server=127.0.0.1:8080,tag=SEETHIS;
+            access_log syslog:server=127.0.0.1:%%PORT_4_UDP%%,tag=SEETHIS;
         }
         location /e2 {
-            error_log syslog:server=127.0.0.1:8080;
-            error_log syslog:server=127.0.0.1:8080;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
         }
         location /a2 {
-            access_log syslog:server=127.0.0.1:8080;
-            access_log syslog:server=127.0.0.1:8080;
+            access_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
+            access_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
         }
         location /a_logf {
-            access_log syslog:server=127.0.0.1:8080 logf;
+            access_log syslog:server=127.0.0.1:%%PORT_4_UDP%% logf;
         }
         location /if {
-            access_log syslog:server=127.0.0.1:8085 logf if=$arg_logme;
+            access_log syslog:server=127.0.0.1:%%PORT_3_UDP%% logf
+                if=$arg_logme;
         }
 
         location /nohostname {
-            access_log syslog:server=127.0.0.1:8080,nohostname;
+            access_log syslog:server=127.0.0.1:%%PORT_4_UDP%%,nohostname;
         }
 
         location /debug {
             limit_req zone=one;
-            error_log syslog:server=127.0.0.1:8080 debug;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%% debug;
         }
         location /info {
             limit_req zone=one;
             limit_req_log_level info;
-            error_log syslog:server=127.0.0.1:8080 info;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%% info;
         }
         location /notice {
             limit_req zone=one;
             limit_req_log_level notice;
-            error_log syslog:server=127.0.0.1:8080 notice;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%% notice;
         }
         location /warn {
             limit_req zone=one;
             limit_req_log_level warn;
-            error_log syslog:server=127.0.0.1:8080 warn;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%% warn;
         }
         location /error {
             limit_req zone=one;
             limit_req_log_level error;
-            error_log syslog:server=127.0.0.1:8080;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
         }
         location /low {
-            error_log syslog:server=127.0.0.1:8080 warn;
-            error_log syslog:server=127.0.0.1:8080;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%% warn;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
         }
         location /dup {
-            error_log syslog:server=127.0.0.1:8080;
-            error_log syslog:server=127.0.0.1:8080;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
         }
         location /high {
-            error_log syslog:server=127.0.0.1:8080 emerg;
-            error_log syslog:server=127.0.0.1:8080;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%% emerg;
+            error_log syslog:server=127.0.0.1:%%PORT_4_UDP%%;
         }
     }
 }
 
 EOF
 
-$t->run_daemon(\&syslog_daemon, 8083, $t, 's_glob.log');
-$t->run_daemon(\&syslog_daemon, 8084, $t, 's_http.log');
-$t->run_daemon(\&syslog_daemon, 8085, $t, 's_if.log');
+$t->run_daemon(\&syslog_daemon, port(1), $t, 's_glob.log');
+$t->run_daemon(\&syslog_daemon, port(2), $t, 's_http.log');
+$t->run_daemon(\&syslog_daemon, port(3), $t, 's_if.log');
 
 $t->waitforfile($t->testdir . '/s_glob.log');
 $t->waitforfile($t->testdir . '/s_http.log');
@@ -226,7 +227,7 @@ like(get_syslog('/nohostname'),
 
 sub syslog_lines {
 	my ($uri, $pattern, $port) = @_;
-	return map { $_ =~ /\Q$pattern\E/g } (get_syslog($uri, $port));
+	return map { $_ =~ /\Q$pattern\E/g } (get_syslog($uri));
 }
 
 sub levels {
@@ -239,20 +240,18 @@ sub levels {
 }
 
 sub get_syslog {
-	my ($uri, $port) = @_;
+	my ($uri) = @_;
 	my ($s);
 	my $rfd = '';
 	my $data = '';
 
-	$port = 8080 unless defined $port;
-
 	eval {
 		local $SIG{ALRM} = sub { die "timeout\n" };
 		local $SIG{PIPE} = sub { die "sigpipe\n" };
 		alarm(1);
 		$s = IO::Socket::INET->new(
 			Proto => 'udp',
-			LocalAddr => "127.0.0.1:$port"
+			LocalAddr => '127.0.0.1:' . port(4)
 		);
 		alarm(0);
 	};