diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-11 07:56:52 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-11 07:56:52 +0000 |
commit | 67026b8131f34dc16043bb0d77cf2aba6567b94f (patch) | |
tree | 89a8450917c3fec2014dac54596aef3b42d8bb8c | |
parent | 86c98f65a2673096f7079ea52c6a823776bea67e (diff) | |
download | ruby-67026b8131f34dc16043bb0d77cf2aba6567b94f.tar.gz |
net/imap: Net::IMAP#disconnect need not do anything if already disconnected
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-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 |