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

ruby-changes:63136

From: Yusuke <ko1@a...>
Date: Sat, 26 Sep 2020 00:27:26 +0900 (JST)
Subject: [ruby-changes:63136] b271bd73e0 (master): test/net/smtp/test_smtp.rb: Stop io leaks

https://git.ruby-lang.org/ruby.git/commit/?id=b271bd73e0

From b271bd73e081e22d1165b18a3fa03a96a9f4e697 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Sat, 26 Sep 2020 00:20:06 +0900
Subject: 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>
```

diff --git a/test/net/smtp/test_smtp.rb b/test/net/smtp/test_smtp.rb
index 507caee..fccf137 100644
--- a/test/net/smtp/test_smtp.rb
+++ b/test/net/smtp/test_smtp.rb
@@ -28,6 +28,14 @@ module Net https://github.com/ruby/ruby/blob/trunk/test/net/smtp/test_smtp.rb#L28
       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 https://github.com/ruby/ruby/blob/trunk/test/net/smtp/test_smtp.rb#L195
     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 https://github.com/ruby/ruby/blob/trunk/test/net/smtp/test_smtp.rb#L227
       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 https://github.com/ruby/ruby/blob/trunk/test/net/smtp/test_smtp.rb#L267
 
     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"
-- 
cgit v0.10.2


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

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