# HG changeset patch # User Andrey Zelenkov # Date 1468345866 -10800 # Node ID a8b8dd6e8ae1a7e479961b50e04d3894ab70760b # Parent e17ffab3febc9cdc9ceb392902bb28e4f15093ac 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. diff --git a/mail_error_log.t b/mail_error_log.t --- 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'); diff --git a/mail_imap.t b/mail_imap.t --- 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(); diff --git a/mail_imap_ssl.t b/mail_imap_ssl.t --- 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)); ############################################################################### diff --git a/mail_pop3.t b/mail_pop3.t --- 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(); diff --git a/mail_resolver.t b/mail_resolver.t --- 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); ############################################################################### diff --git a/mail_smtp.t b/mail_smtp.t --- 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(); diff --git a/mail_smtp_xclient.t b/mail_smtp_xclient.t --- 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