1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/net/imap/test_imap.rb: Don't ignore exceptions on server

threads.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-11-10 15:22:29 +00:00
parent 9bf5457481
commit 976574413a
2 changed files with 181 additions and 223 deletions

View file

@ -1,3 +1,8 @@
Tue Nov 11 00:21:50 2014 Tanaka Akira <akr@fsij.org>
* test/net/imap/test_imap.rb: Don't ignore exceptions on server
threads.
Mon Nov 10 23:34:13 2014 Tanaka Akira <akr@fsij.org> Mon Nov 10 23:34:13 2014 Tanaka Akira <akr@fsij.org>
* test/net/ftp/test_ftp.rb (create_ftp_server): Don't ignore * test/net/ftp/test_ftp.rb (create_ftp_server): Don't ignore

View file

@ -11,9 +11,14 @@ class IMAPTest < Test::Unit::TestCase
def setup def setup
@do_not_reverse_lookup = Socket.do_not_reverse_lookup @do_not_reverse_lookup = Socket.do_not_reverse_lookup
Socket.do_not_reverse_lookup = true Socket.do_not_reverse_lookup = true
@threads = []
end end
def teardown def teardown
if !@threads.empty?
assert_join_threads(@threads)
end
ensure
Socket.do_not_reverse_lookup = @do_not_reverse_lookup Socket.do_not_reverse_lookup = @do_not_reverse_lookup
end end
@ -127,8 +132,7 @@ class IMAPTest < Test::Unit::TestCase
def test_unexpected_eof def test_unexpected_eof
server = create_tcp_server server = create_tcp_server
port = server.addr[1] port = server.addr[1]
ths = Thread.start do @threads << Thread.start do
begin
sock = server.accept sock = server.accept
begin begin
sock.print("* OK test server\r\n") sock.print("* OK test server\r\n")
@ -137,11 +141,9 @@ class IMAPTest < Test::Unit::TestCase
# sock.print("RUBY0001 OK LOGOUT completed\r\n") # sock.print("RUBY0001 OK LOGOUT completed\r\n")
ensure ensure
sock.close sock.close
end server.close
rescue
end end
end end
begin
begin begin
imap = Net::IMAP.new(SERVER_ADDR, :port => port) imap = Net::IMAP.new(SERVER_ADDR, :port => port)
assert_raise(EOFError) do assert_raise(EOFError) do
@ -150,18 +152,13 @@ class IMAPTest < Test::Unit::TestCase
ensure ensure
imap.disconnect if imap imap.disconnect if imap
end end
ensure
server.close
ths.join
end
end end
def test_idle def test_idle
server = create_tcp_server server = create_tcp_server
port = server.addr[1] port = server.addr[1]
requests = [] requests = []
ths = Thread.start do @threads << Thread.start do
begin
sock = server.accept sock = server.accept
begin begin
sock.print("* OK test server\r\n") sock.print("* OK test server\r\n")
@ -176,11 +173,10 @@ class IMAPTest < Test::Unit::TestCase
sock.print("RUBY0002 OK LOGOUT completed\r\n") sock.print("RUBY0002 OK LOGOUT completed\r\n")
ensure ensure
sock.close sock.close
end server.close
rescue
end end
end end
begin
begin begin
imap = Net::IMAP.new(SERVER_ADDR, :port => port) imap = Net::IMAP.new(SERVER_ADDR, :port => port)
responses = [] responses = []
@ -203,18 +199,13 @@ class IMAPTest < Test::Unit::TestCase
ensure ensure
imap.disconnect if imap imap.disconnect if imap
end end
ensure
server.close
ths.join
end
end end
def test_exception_during_idle def test_exception_during_idle
server = create_tcp_server server = create_tcp_server
port = server.addr[1] port = server.addr[1]
requests = [] requests = []
ths = Thread.start do @threads << Thread.start do
begin
sock = server.accept sock = server.accept
begin begin
sock.print("* OK test server\r\n") sock.print("* OK test server\r\n")
@ -229,11 +220,9 @@ class IMAPTest < Test::Unit::TestCase
sock.print("RUBY0002 OK LOGOUT completed\r\n") sock.print("RUBY0002 OK LOGOUT completed\r\n")
ensure ensure
sock.close sock.close
end server.close
rescue
end end
end end
begin
begin begin
imap = Net::IMAP.new(SERVER_ADDR, :port => port) imap = Net::IMAP.new(SERVER_ADDR, :port => port)
begin begin
@ -242,7 +231,7 @@ class IMAPTest < Test::Unit::TestCase
in_idle = false in_idle = false
exception_raised = false exception_raised = false
c = m.new_cond c = m.new_cond
thw = Thread.start do @threads << Thread.start do
m.synchronize do m.synchronize do
until in_idle until in_idle
c.wait(0.1) c.wait(0.1)
@ -268,29 +257,21 @@ class IMAPTest < Test::Unit::TestCase
imap.logout imap.logout
ensure ensure
imap.disconnect if imap imap.disconnect if imap
thw.join
end
ensure
server.close
ths.join
end end
end end
def test_idle_done_not_during_idle def test_idle_done_not_during_idle
server = create_tcp_server server = create_tcp_server
port = server.addr[1] port = server.addr[1]
ths = Thread.start do @threads << Thread.start do
begin
sock = server.accept sock = server.accept
begin begin
sock.print("* OK test server\r\n") sock.print("* OK test server\r\n")
ensure ensure
sock.close sock.close
end server.close
rescue
end end
end end
begin
begin begin
imap = Net::IMAP.new(SERVER_ADDR, :port => port) imap = Net::IMAP.new(SERVER_ADDR, :port => port)
assert_raise(Net::IMAP::Error) do assert_raise(Net::IMAP::Error) do
@ -299,17 +280,12 @@ class IMAPTest < Test::Unit::TestCase
ensure ensure
imap.disconnect if imap imap.disconnect if imap
end end
ensure
server.close
ths.join
end
end end
def test_unexpected_bye def test_unexpected_bye
server = create_tcp_server server = create_tcp_server
port = server.addr[1] port = server.addr[1]
ths = Thread.start do @threads << Thread.start do
begin
sock = server.accept sock = server.accept
begin begin
sock.print("* OK Gimap ready for requests from 75.101.246.151 33if2752585qyk.26\r\n") sock.print("* OK Gimap ready for requests from 75.101.246.151 33if2752585qyk.26\r\n")
@ -317,28 +293,21 @@ class IMAPTest < Test::Unit::TestCase
sock.print("* BYE System Error 33if2752585qyk.26\r\n") sock.print("* BYE System Error 33if2752585qyk.26\r\n")
ensure ensure
sock.close sock.close
end server.close
rescue
end end
end end
begin
begin begin
imap = Net::IMAP.new(SERVER_ADDR, :port => port) imap = Net::IMAP.new(SERVER_ADDR, :port => port)
assert_raise(Net::IMAP::ByeResponseError) do assert_raise(Net::IMAP::ByeResponseError) do
imap.login("user", "password") imap.login("user", "password")
end end
end end
ensure
server.close
ths.join
end
end end
def test_exception_during_shutdown def test_exception_during_shutdown
server = create_tcp_server server = create_tcp_server
port = server.addr[1] port = server.addr[1]
ths = Thread.start do @threads << Thread.start do
begin
sock = server.accept sock = server.accept
begin begin
sock.print("* OK test server\r\n") sock.print("* OK test server\r\n")
@ -347,11 +316,9 @@ class IMAPTest < Test::Unit::TestCase
sock.print("RUBY0001 OK LOGOUT completed\r\n") sock.print("RUBY0001 OK LOGOUT completed\r\n")
ensure ensure
sock.close sock.close
end server.close
rescue
end end
end end
begin
begin begin
imap = Net::IMAP.new(SERVER_ADDR, :port => port) imap = Net::IMAP.new(SERVER_ADDR, :port => port)
imap.instance_eval do imap.instance_eval do
@ -367,10 +334,6 @@ class IMAPTest < Test::Unit::TestCase
imap.disconnect imap.disconnect
end end
end end
ensure
server.close
ths.join
end
end end
def test_connection_closed_during_idle def test_connection_closed_during_idle
@ -378,23 +341,26 @@ class IMAPTest < Test::Unit::TestCase
port = server.addr[1] port = server.addr[1]
requests = [] requests = []
sock = nil sock = nil
ths = Thread.start do threads = []
threads << Thread.start do
begin begin
sock = server.accept sock = server.accept
sock.print("* OK test server\r\n") sock.print("* OK test server\r\n")
requests.push(sock.gets) requests.push(sock.gets)
sock.print("+ idling\r\n") sock.print("+ idling\r\n")
rescue rescue IOError # sock is closed by another thread
ensure
server.close
end end
end end
begin threads << Thread.start do
imap = Net::IMAP.new(SERVER_ADDR, :port => port) imap = Net::IMAP.new(SERVER_ADDR, :port => port)
begin begin
m = Monitor.new m = Monitor.new
in_idle = false in_idle = false
exception_raised = false exception_raised = false
c = m.new_cond c = m.new_cond
thw = Thread.start do threads << Thread.start do
m.synchronize do m.synchronize do
until in_idle until in_idle
c.wait(0.1) c.wait(0.1)
@ -418,34 +384,28 @@ class IMAPTest < Test::Unit::TestCase
assert_equal("RUBY0001 IDLE\r\n", requests[0]) assert_equal("RUBY0001 IDLE\r\n", requests[0])
ensure ensure
imap.disconnect if imap imap.disconnect if imap
thw.join
end end
end
assert_join_threads(threads)
ensure ensure
server.close
if sock && !sock.closed? if sock && !sock.closed?
sock.close sock.close
end end
ths.join
end
end end
def test_connection_closed_without_greeting def test_connection_closed_without_greeting
server = create_tcp_server server = create_tcp_server
port = server.addr[1] port = server.addr[1]
ths = Thread.start do @threads << Thread.start do
begin begin
sock = server.accept sock = server.accept
sock.close sock.close
rescue
end
end
begin
assert_raise(Net::IMAP::Error) do
Net::IMAP.new(SERVER_ADDR, :port => port)
end
ensure ensure
server.close server.close
ths.join end
end
assert_raise(Net::IMAP::Error) do
Net::IMAP.new(SERVER_ADDR, :port => port)
end end
end end
@ -482,7 +442,7 @@ class IMAPTest < Test::Unit::TestCase
ensure ensure
sock.close sock.close
end end
rescue rescue Errno::EPIPE
end end
end end
begin begin
@ -501,8 +461,7 @@ class IMAPTest < Test::Unit::TestCase
def starttls_test def starttls_test
server = create_tcp_server server = create_tcp_server
port = server.addr[1] port = server.addr[1]
ths = Thread.start do @threads << Thread.start do
begin
sock = server.accept sock = server.accept
begin begin
sock.print("* OK test server\r\n") sock.print("* OK test server\r\n")
@ -524,21 +483,15 @@ class IMAPTest < Test::Unit::TestCase
sock.print("RUBY0002 OK LOGOUT completed\r\n") sock.print("RUBY0002 OK LOGOUT completed\r\n")
ensure ensure
sock.close sock.close
end server.close
rescue
end end
end end
begin
begin begin
imap = yield(port) imap = yield(port)
imap.logout if !imap.disconnected? imap.logout if !imap.disconnected?
ensure ensure
imap.disconnect if imap && !imap.disconnected? imap.disconnect if imap && !imap.disconnected?
end end
ensure
server.close
ths.join
end
end end
def create_tcp_server def create_tcp_server