diff options
-rw-r--r-- | lib/net/imap.rb | 1 | ||||
-rw-r--r-- | test/net/imap/test_imap.rb | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/net/imap.rb b/lib/net/imap.rb index f069ec5149..8c831cf703 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -325,6 +325,7 @@ module Net # Disconnects from the server. def disconnect + return if disconnected? begin begin # try to call SSL::SSLSocket#io. diff --git a/test/net/imap/test_imap.rb b/test/net/imap/test_imap.rb index 35e5ed8982..3224da65a1 100644 --- a/test/net/imap/test_imap.rb +++ b/test/net/imap/test_imap.rb @@ -526,6 +526,33 @@ class IMAPTest < Test::Unit::TestCase end end + def test_disconnect + server = create_tcp_server + port = server.addr[1] + @threads << Thread.start do + sock = server.accept + begin + sock.print("* OK test server\r\n") + sock.gets + sock.print("* BYE terminating connection\r\n") + sock.print("RUBY0001 OK LOGOUT completed\r\n") + ensure + sock.close + server.close + end + end + begin + imap = Net::IMAP.new(SERVER_ADDR, :port => port) + imap.logout + imap.disconnect + assert_equal(true, imap.disconnected?) + imap.disconnect + assert_equal(true, imap.disconnected?) + ensure + imap.disconnect if imap && !imap.disconnected? + end + end + private def imaps_test |