Skip to content

Commit 7b102f8

Browse files
committed
Tests: worker_shutdown_timeout within the mail module.
1 parent 3ea332e commit 7b102f8

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

lib/Test/Nginx/IMAP.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use warnings;
1010
use strict;
1111

1212
use Test::More qw//;
13+
use IO::Select;
1314
use IO::Socket;
1415
use Socket qw/ CRLF /;
1516

@@ -86,6 +87,11 @@ sub ok {
8687
Test::More->builder->like($self->read(), qr/^\S+ OK/, @_);
8788
}
8889

90+
sub can_read {
91+
my ($self, $timo) = @_;
92+
IO::Select->new($self->{_socket})->can_read($timo || 3);
93+
}
94+
8995
###############################################################################
9096

9197
sub imap_test_daemon {

lib/Test/Nginx/POP3.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use warnings;
1010
use strict;
1111

1212
use Test::More qw//;
13+
use IO::Select;
1314
use IO::Socket;
1415
use Socket qw/ CRLF /;
1516

@@ -86,6 +87,11 @@ sub ok {
8687
Test::More->builder->like($self->read(), qr/^\+OK/, @_);
8788
}
8889

90+
sub can_read {
91+
my ($self, $timo) = @_;
92+
IO::Select->new($self->{_socket})->can_read($timo || 3);
93+
}
94+
8995
###############################################################################
9096

9197
sub pop3_test_daemon {

lib/Test/Nginx/SMTP.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use warnings;
1010
use strict;
1111

1212
use Test::More qw//;
13+
use IO::Select;
1314
use IO::Socket;
1415
use Socket qw/ CRLF /;
1516

@@ -90,6 +91,11 @@ sub authok {
9091
Test::More->builder->like($self->read(), qr/^235 /, @_);
9192
}
9293

94+
sub can_read {
95+
my ($self, $timo) = @_;
96+
IO::Select->new($self->{_socket})->can_read($timo || 3);
97+
}
98+
9399
###############################################################################
94100

95101
sub smtp_test_daemon {

worker_shutdown_timeout_mail.t

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/perl
2+
3+
# (C) Sergey Kandaurov
4+
# (C) Nginx, Inc.
5+
6+
# Tests for worker_shutdown_timeout directive within the mail module.
7+
8+
###############################################################################
9+
10+
use warnings;
11+
use strict;
12+
13+
use Test::More;
14+
15+
use MIME::Base64;
16+
17+
BEGIN { use FindBin; chdir($FindBin::Bin); }
18+
19+
use lib 'lib';
20+
use Test::Nginx;
21+
use Test::Nginx::SMTP;
22+
23+
###############################################################################
24+
25+
select STDERR; $| = 1;
26+
select STDOUT; $| = 1;
27+
28+
local $SIG{PIPE} = 'IGNORE';
29+
30+
my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/)->plan(4)
31+
->write_file_expand('nginx.conf', <<'EOF');
32+
33+
%%TEST_GLOBALS%%
34+
35+
daemon off;
36+
worker_shutdown_timeout 10ms;
37+
38+
events {
39+
}
40+
41+
mail {
42+
proxy_pass_error_message on;
43+
auth_http http://127.0.0.1:8080/mail/auth;
44+
xclient off;
45+
46+
server {
47+
listen 127.0.0.1:8025;
48+
protocol smtp;
49+
}
50+
}
51+
52+
http {
53+
%%TEST_GLOBALS_HTTP%%
54+
55+
server {
56+
listen 127.0.0.1:8080;
57+
server_name localhost;
58+
59+
location = /mail/auth {
60+
add_header Auth-Status OK;
61+
add_header Auth-Server 127.0.0.1;
62+
add_header Auth-Port %%PORT_8026%%;
63+
add_header Auth-Wait 1;
64+
return 204;
65+
}
66+
}
67+
}
68+
69+
EOF
70+
71+
$t->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon);
72+
$t->run()->waitforsocket('127.0.0.1:' . port(8026));
73+
74+
###############################################################################
75+
76+
my $s = Test::Nginx::SMTP->new();
77+
$s->check(qr/^220 /, "greeting");
78+
79+
$s->send('EHLO example.com');
80+
$s->check(qr/^250 /, "ehlo");
81+
82+
$s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
83+
$s->authok('auth plain');
84+
85+
$t->reload();
86+
87+
TODO: {
88+
local $TODO = 'not yet' unless $t->has_version('1.13.7');
89+
90+
ok($s->can_read(), 'mail connection shutdown');
91+
92+
}
93+
94+
undef $s;
95+
96+
###############################################################################

0 commit comments

Comments
 (0)