[Bps-public-commit] Net-IMAP-Server branch, master, updated. 1.32-2-gcc73819
Alex Vandiver
alexmv at bestpractical.com
Sat Apr 7 19:46:28 EDT 2012
The branch, master has been updated
via cc73819f39db29299610c508b0479d653899ed29 (commit)
via 3e9402fb101381c52a1d4bb5be1e86e1ebd1c364 (commit)
from 25ca47e117e10948d639bc37dcb48c6c5681b0e8 (commit)
Summary of changes:
Changes | 4 ++++
lib/Net/IMAP/Server.pm | 2 +-
t/lib/Net/IMAP/Server/Test.pm | 19 +++++++++++++++++++
t/rfc-6.1.3-logout.t | 25 +++++++++++--------------
4 files changed, 35 insertions(+), 15 deletions(-)
- Log -----------------------------------------------------------------
commit 3e9402fb101381c52a1d4bb5be1e86e1ebd1c364
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Fri Apr 6 03:15:31 2012 -0400
Use recv() with MSG_PEEK to check for half-closed TCP sockets in test
After the client sends QUIT, the server closes its half of the
connection. This leaves the connection in TCP status CLOSE_WAIT from
the point of view of the client. Testing that the connection is
half-closed is slightly complicated; previously, we faked it by forcing
a write failure.
Use the low-level recv() function to examine if there is any data
waiting in the TCP buffer, of if there can ever be. If the connection
is half-closed, it will return 0; otherwise, the server -> client
connection is understood to be still open.
diff --git a/t/lib/Net/IMAP/Server/Test.pm b/t/lib/Net/IMAP/Server/Test.pm
index 5725b48..2642ff4 100644
--- a/t/lib/Net/IMAP/Server/Test.pm
+++ b/t/lib/Net/IMAP/Server/Test.pm
@@ -4,6 +4,7 @@ use base qw/Test::More/;
use strict;
use warnings;
+use Socket;
use IO::Socket::SSL;
use Time::HiRes qw();
@@ -75,6 +76,24 @@ sub connect {
return;
}
+sub connected {
+ my $class = shift;
+ my $socket = $class->get_socket;
+ return 0 unless $socket->connected;
+
+ my $buf;
+ # We intentionally use the non-OO recv function here,
+ # IO::Socket::SSL doesn't define a recv, and we want the low-level,
+ # not under a layer version, anyways.
+ my $waiting = recv($socket, $buf, 1, MSG_PEEK | MSG_DONTWAIT);
+
+ # Undef if there's nothing currently waiting
+ return 1 if not defined $waiting;
+
+ # True if there is, false if the connection is closed
+ return $waiting;
+}
+
sub get_socket {
my $class = shift;
return $class->builder->{$class->socket_key};
diff --git a/t/rfc-6.1.3-logout.t b/t/rfc-6.1.3-logout.t
index 58b1e7e..eb67d7e 100644
--- a/t/rfc-6.1.3-logout.t
+++ b/t/rfc-6.1.3-logout.t
@@ -12,51 +12,48 @@ $t->connect_ok( "Non-SSL connection OK",
Class => "IO::Socket::INET",
PeerPort => $t->PORT,
);
-ok($t->get_socket->connected, "Is connected");
+ok($t->connected, "Is connected");
$t->cmd_like(
"LOGOUT",
"* BYE",
"tag OK",
);
-{
- local $TODO = "It doesn't realize it has been disconnected";
- ok(!$t->get_socket->connected, "Is still connected");
- $t->get_socket->print("\n");
-}
-ok(!$t->get_socket->connected, "Is still connected");
+ok(!$t->connected, "Is now disconnected");
# SSL connection
$t->connect_ok;
-ok($t->get_socket->connected, "Is connected");
+ok($t->connected, "Is connected");
$t->cmd_like(
"LOGOUT",
"* BYE",
"tag OK",
);
-{
- local $TODO = "It doesn't realize it has been disconnected";
- ok(!$t->get_socket->connected, "Is still connected");
- $t->get_socket->print("\n");
-}
-ok(!$t->get_socket->connected, "Is still connected");
+ok(!$t->connected, "Is now disconnected");
# Logged in
$t->connect_ok;
+ok($t->connected, "Is now connected");
$t->cmd_ok("LOGIN username password");
+ok($t->connected, "Still connected after LOGIN");
$t->cmd_like(
"LOGOUT",
"* BYE",
"tag OK",
);
+ok(!$t->connected, "Is now disconnected");
# And selected
$t->connect_ok;
+ok($t->connected, "Is now connected");
$t->cmd_ok("LOGIN username password");
+ok($t->connected, "Still connected after LOGIN");
$t->cmd_ok("SELECT INBOX");
+ok($t->connected, "Still connected after SELECT");
$t->cmd_like(
"LOGOUT",
"* BYE",
"tag OK",
);
+ok(!$t->connected, "Is now disconnected");
done_testing;
commit cc73819f39db29299610c508b0479d653899ed29
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Sat Apr 7 19:42:09 2012 -0400
Version 1.33 releng
diff --git a/Changes b/Changes
index 5c71514..bf878c5 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
Revision history for Net-IMAP-Server
+1.33 Sat Apr 07 19:37:17 2012
+ * Test fixes; use recv() with MSG_PEEK | MSG_DONTWAIT to
+ determine if a TCP connection is in state CLOSE_WAIT
+
1.32 Fri Apr 06 00:45:17 2012
* Trim newlines passed to all commands, including continuation
lines
diff --git a/lib/Net/IMAP/Server.pm b/lib/Net/IMAP/Server.pm
index b5bbbfe..682ab25 100644
--- a/lib/Net/IMAP/Server.pm
+++ b/lib/Net/IMAP/Server.pm
@@ -8,7 +8,7 @@ use base qw/Net::Server::Coro Class::Accessor/;
use UNIVERSAL::require;
use Coro;
-our $VERSION = '1.32';
+our $VERSION = '1.33';
=head1 NAME
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list