[前][次][番号順一覧][スレッド一覧]

ruby-changes:46548

From: shugo <ko1@a...>
Date: Thu, 11 May 2017 16:56:59 +0900 (JST)
Subject: [ruby-changes:46548] shugo:r58663 (trunk): net/imap: Net::IMAP#disconnect need not do anything if already disconnected

shugo	2017-05-11 16:56:52 +0900 (Thu, 11 May 2017)

  New Revision: 58663

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58663

  Log:
    net/imap: Net::IMAP#disconnect need not do anything if already disconnected

  Modified files:
    trunk/lib/net/imap.rb
    trunk/test/net/imap/test_imap.rb
Index: lib/net/imap.rb
===================================================================
--- lib/net/imap.rb	(revision 58662)
+++ lib/net/imap.rb	(revision 58663)
@@ -325,6 +325,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/imap.rb#L325
 
     # Disconnects from the server.
     def disconnect
+      return if disconnected?
       begin
         begin
           # try to call SSL::SSLSocket#io.
Index: test/net/imap/test_imap.rb
===================================================================
--- test/net/imap/test_imap.rb	(revision 58662)
+++ test/net/imap/test_imap.rb	(revision 58663)
@@ -526,6 +526,33 @@ class IMAPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/imap/test_imap.rb#L526
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]