summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2020-09-26 00:20:06 +0900
committerYusuke Endoh <mame@ruby-lang.org>2020-09-26 00:20:06 +0900
commitb271bd73e081e22d1165b18a3fa03a96a9f4e697 (patch)
tree26b898f99fdcc6f552e6ec137300461d5df00279 /test
parent8119e5b0e6a1341a9130c14604ade5acca6d21f3 (diff)
test/net/smtp/test_smtp.rb: Stop io leaks
`make test-all` was very noisy by warnings like ``` Leaked file descriptor: Net::TestSMTP#test_start_with_position_argument: 6 : #<TCPSocket:fd 6, AF_INET, 127.0.0.1, 43770> ```
Diffstat (limited to 'test')
-rw-r--r--test/net/smtp/test_smtp.rb26
1 files changed, 17 insertions, 9 deletions
diff --git a/test/net/smtp/test_smtp.rb b/test/net/smtp/test_smtp.rb
index 507caee025..fccf137cdc 100644
--- a/test/net/smtp/test_smtp.rb
+++ b/test/net/smtp/test_smtp.rb
@@ -28,6 +28,14 @@ module Net
end
end
+ def setup
+ @server_threads = []
+ end
+
+ def teardown
+ @server_threads.each {|th| th.join }
+ end
+
def test_critical
smtp = Net::SMTP.new 'localhost', 25
@@ -187,25 +195,25 @@ module Net
def test_start
port = fake_server_start
smtp = Net::SMTP.start('localhost', port)
- smtp.quit
+ smtp.finish
end
def test_start_with_position_argument
port = fake_server_start(helo: 'myname', user: 'account', password: 'password')
smtp = Net::SMTP.start('localhost', port, 'myname', 'account', 'password', :plain)
- smtp.quit
+ smtp.finish
end
def test_start_with_keyword_argument
port = fake_server_start(helo: 'myname', user: 'account', password: 'password')
smtp = Net::SMTP.start('localhost', port, helo: 'myname', user: 'account', secret: 'password', authtype: :plain)
- smtp.quit
+ smtp.finish
end
def test_start_password_is_secret
port = fake_server_start(helo: 'myname', user: 'account', password: 'password')
smtp = Net::SMTP.start('localhost', port, helo: 'myname', user: 'account', password: 'password', authtype: :plain)
- smtp.quit
+ smtp.finish
end
def test_start_invalid_number_of_arguments
@@ -219,28 +227,28 @@ module Net
port = fake_server_start
smtp = Net::SMTP.new('localhost', port)
smtp.start
- smtp.quit
+ smtp.finish
end
def test_start_instance_with_position_argument
port = fake_server_start(helo: 'myname', user: 'account', password: 'password')
smtp = Net::SMTP.new('localhost', port)
smtp.start('myname', 'account', 'password', :plain)
- smtp.quit
+ smtp.finish
end
def test_start_instance_with_keyword_argument
port = fake_server_start(helo: 'myname', user: 'account', password: 'password')
smtp = Net::SMTP.new('localhost', port)
smtp.start(helo: 'myname', user: 'account', secret: 'password', authtype: :plain)
- smtp.quit
+ smtp.finish
end
def test_start_instance_password_is_secret
port = fake_server_start(helo: 'myname', user: 'account', password: 'password')
smtp = Net::SMTP.new('localhost', port)
smtp.start(helo: 'myname', user: 'account', password: 'password', authtype: :plain)
- smtp.quit
+ smtp.finish
end
def test_start_instance_invalid_number_of_arguments
@@ -259,7 +267,7 @@ module Net
def fake_server_start(helo: 'localhost', user: nil, password: nil)
servers = Socket.tcp_server_sockets('localhost', 0)
- Thread.start do
+ @server_threads << Thread.start do
Thread.current.abort_on_exception = true
sock = accept(servers)
sock.puts "220 ready\r\n"