changeset 976:a8b8dd6e8ae1

Tests: changed startup order in mail tests for consistency. Notably, run_daemon() is postponed until after write_file_expand(). Also added waitforsocket() to avoid startup race.
author Andrey Zelenkov <zelenkov@nginx.com>
date Tue, 12 Jul 2016 20:51:06 +0300
parents e17ffab3febc
children 6abe7be6d2c1
files mail_error_log.t mail_imap.t mail_imap_ssl.t mail_pop3.t mail_resolver.t mail_smtp.t mail_smtp_xclient.t
diffstat 7 files changed, 34 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/mail_error_log.t
+++ b/mail_error_log.t
@@ -27,8 +27,7 @@ select STDOUT; $| = 1;
 
 plan(skip_all => 'win32') if $^O eq 'MSWin32';
 
-my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/)
-	->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon, port(8144));
+my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/);
 
 plan(skip_all => 'no error_log') unless $t->has_version('1.9.0');
 
@@ -90,9 +89,11 @@ open STDERR, '>', $t->testdir() . '/stde
 open my $stderr, '<', $t->testdir() . '/stderr'
 	or die "Can't open stderr file: $!";
 
+$t->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon);
 $t->run_daemon(\&syslog_daemon, port(8081), $t, 's_glob.log');
 $t->run_daemon(\&syslog_daemon, port(8082), $t, 's_info.log');
 
+$t->waitforsocket('127.0.0.1:' . port(8144));
 $t->waitforfile($t->testdir . '/s_glob.log');
 $t->waitforfile($t->testdir . '/s_info.log');
 
--- a/mail_imap.t
+++ b/mail_imap.t
@@ -26,10 +26,8 @@ select STDOUT; $| = 1;
 
 local $SIG{PIPE} = 'IGNORE';
 
-my $t = Test::Nginx->new()
-	->has(qw/mail imap http rewrite/)->plan(9)
-	->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon, port(8144))
-	->write_file_expand('nginx.conf', <<'EOF')->run();
+my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/)->plan(9)
+	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
 
@@ -78,6 +76,9 @@ http {
 
 EOF
 
+$t->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon);
+$t->run()->waitforsocket('127.0.0.1:' . port(8144));
+
 ###############################################################################
 
 my $s = Test::Nginx::IMAP->new();
--- a/mail_imap_ssl.t
+++ b/mail_imap_ssl.t
@@ -33,12 +33,9 @@ plan(skip_all => 'IO::Socket::SSL too ol
 
 local $SIG{PIPE} = 'IGNORE';
 
-my $t = Test::Nginx->new()
-	->has(qw/mail mail_ssl imap http rewrite/)->has_daemon('openssl')
-	->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon, port(8144))
-	->plan(12);
-
-$t->write_file_expand('nginx.conf', <<'EOF');
+my $t = Test::Nginx->new()->has(qw/mail mail_ssl imap http rewrite/)
+	->has_daemon('openssl')->plan(12)
+	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
 
@@ -138,7 +135,8 @@ foreach my $name ('1.example.com', '2.ex
 		or die "Can't create certificate for $name: $!\n";
 }
 
-$t->run();
+$t->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon);
+$t->run()->waitforsocket('127.0.0.1:' . port(8144));
 
 ###############################################################################
 
--- a/mail_pop3.t
+++ b/mail_pop3.t
@@ -26,10 +26,8 @@ select STDOUT; $| = 1;
 
 local $SIG{PIPE} = 'IGNORE';
 
-my $t = Test::Nginx->new()
-	->has(qw/mail pop3 http rewrite/)->plan(8)
-	->run_daemon(\&Test::Nginx::POP3::pop3_test_daemon, port(8111))
-	->write_file_expand('nginx.conf', <<'EOF')->run();
+my $t = Test::Nginx->new()->has(qw/mail pop3 http rewrite/)->plan(8)
+	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
 
@@ -78,6 +76,9 @@ http {
 
 EOF
 
+$t->run_daemon(\&Test::Nginx::POP3::pop3_test_daemon);
+$t->run()->waitforsocket('127.0.0.1:' . port(8111));
+
 ###############################################################################
 
 my $s = Test::Nginx::POP3->new();
--- a/mail_resolver.t
+++ b/mail_resolver.t
@@ -25,10 +25,8 @@ select STDOUT; $| = 1;
 
 local $SIG{PIPE} = 'IGNORE';
 
-my $t = Test::Nginx->new()->has(qw/mail smtp http rewrite/)
-	->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon, port(8026));
-
-$t->write_file_expand('nginx.conf', <<'EOF');
+my $t = Test::Nginx->new()->has(qw/mail smtp http rewrite/)->plan(8)
+	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
 
@@ -116,16 +114,13 @@ http {
 
 EOF
 
-for (8081 .. 8087) {
-	$t->run_daemon(\&dns_daemon, port($_), $t);
-}
+$t->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon);
+$t->run_daemon(\&dns_daemon, port($_), $t) foreach (8081 .. 8087);
+
 $t->run();
 
-for (8081 .. 8087) {
-	$t->waitforfile($t->testdir . '/' . port($_));
-}
-
-$t->plan(8);
+$t->waitforsocket('127.0.0.1:' . port(8026));
+$t->waitforfile($t->testdir . '/' . port($_)) foreach (8081 .. 8087);
 
 ###############################################################################
 
--- a/mail_smtp.t
+++ b/mail_smtp.t
@@ -27,10 +27,8 @@ select STDOUT; $| = 1;
 
 local $SIG{PIPE} = 'IGNORE';
 
-my $t = Test::Nginx->new()
-	->has(qw/mail smtp http rewrite/)->plan(25)
-	->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon, port(8026))
-	->write_file_expand('nginx.conf', <<'EOF')->run();
+my $t = Test::Nginx->new()->has(qw/mail smtp http rewrite/)->plan(25)
+	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
 
@@ -81,6 +79,9 @@ http {
 
 EOF
 
+$t->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon);
+$t->run()->waitforsocket('127.0.0.1:' . port(8026));
+
 ###############################################################################
 
 my $s = Test::Nginx::SMTP->new();
--- a/mail_smtp_xclient.t
+++ b/mail_smtp_xclient.t
@@ -25,8 +25,7 @@ select STDOUT; $| = 1;
 local $SIG{PIPE} = 'IGNORE';
 
 my $t = Test::Nginx->new()->has(qw/mail smtp http rewrite/)->plan(6)
-	->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon, port(8026))
-	->write_file_expand('nginx.conf', <<'EOF')->run();
+	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
 
@@ -66,6 +65,9 @@ http {
 
 EOF
 
+$t->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon);
+$t->run()->waitforsocket('127.0.0.1:' . port(8026));
+
 ###############################################################################
 
 # When XCLIENT's HELO= argument isn't used, the  following combinations may be