summaryrefslogtreecommitdiff
path: root/test/net/imap
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-24 09:09:04 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-24 09:09:04 +0000
commit9914a16ca941f47b9fa32874933594a59cf65267 (patch)
tree9d0e81ef4f915e2f9dab87583bce94e7474eb342 /test/net/imap
parentbdd52721b3fc5cfeb0602f7127ade39afa759a3e (diff)
* lib/net/imap.rb (idle): leaves IDLE in a ensure clause. a patch
from Eric Hodel. * test/net/imap/test_imap.rb (setup, teardown): turn on Socket.do_not_reverse_lookup in tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/net/imap')
-rw-r--r--test/net/imap/test_imap.rb94
1 files changed, 94 insertions, 0 deletions
diff --git a/test/net/imap/test_imap.rb b/test/net/imap/test_imap.rb
index e4e1c25ca0a..882487881d5 100644
--- a/test/net/imap/test_imap.rb
+++ b/test/net/imap/test_imap.rb
@@ -6,6 +6,15 @@ class IMAPTest < Test::Unit::TestCase
SERVER_KEY = File.expand_path("server.key", File.dirname(__FILE__))
SERVER_CERT = File.expand_path("server.crt", File.dirname(__FILE__))
+ def setup
+ @do_not_reverse_lookup = Socket.do_not_reverse_lookup
+ Socket.do_not_reverse_lookup = true
+ end
+
+ def teardown
+ Socket.do_not_reverse_lookup = @do_not_reverse_lookup
+ end
+
def test_encode_utf7
utf8 = "\357\274\241\357\274\242\357\274\243".force_encoding("UTF-8")
s = Net::IMAP.encode_utf7(utf8)
@@ -176,6 +185,91 @@ class IMAPTest < Test::Unit::TestCase
end
end
+ def test_exception_during_idle
+ server = TCPServer.new(0)
+ port = server.addr[1]
+ requests = []
+ Thread.start do
+ begin
+ sock = server.accept
+ begin
+ sock.print("* OK test server\r\n")
+ requests.push(sock.gets)
+ sock.print("+ idling\r\n")
+ sock.print("* 3 EXISTS\r\n")
+ sock.print("* 2 EXPUNGE\r\n")
+ requests.push(sock.gets)
+ sock.print("RUBY0001 OK IDLE terminated\r\n")
+ sock.gets
+ sock.print("* BYE terminating connection\r\n")
+ sock.print("RUBY0002 OK LOGOUT completed\r\n")
+ ensure
+ sock.close
+ end
+ rescue
+ end
+ end
+ begin
+ begin
+ imap = Net::IMAP.new("localhost", :port => port)
+ begin
+ th = Thread.current
+ m = Monitor.new
+ c = m.new_cond
+ Thread.start do
+ m.synchronize do
+ c.wait
+ end
+ th.raise(Interrupt)
+ end
+ imap.idle do |res|
+ m.synchronize do
+ c.signal
+ end
+ end
+ rescue Interrupt
+ end
+ assert_equal(2, requests.length)
+ assert_equal("RUBY0001 IDLE\r\n", requests[0])
+ assert_equal("DONE\r\n", requests[1])
+ imap.logout
+ ensure
+ imap.disconnect if imap
+ end
+ ensure
+ server.close
+ end
+ end
+
+ def test_idle_done_not_during_idle
+ server = TCPServer.new(0)
+ port = server.addr[1]
+ requests = []
+ Thread.start do
+ begin
+ sock = server.accept
+ begin
+ sock.print("* OK test server\r\n")
+ ensure
+ sock.close
+ end
+ rescue
+ end
+ end
+ begin
+ begin
+ imap = Net::IMAP.new("localhost", :port => port)
+ assert_raise(Net::IMAP::Error) do
+ imap.idle_done
+ end
+ ensure
+ imap.disconnect if imap
+ end
+ ensure
+ server.close
+ end
+ end
+
private
def imaps_test