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

ruby-changes:36184

From: nobu <ko1@a...>
Date: Tue, 4 Nov 2014 16:24:14 +0900 (JST)
Subject: [ruby-changes:36184] nobu:r48265 (trunk): test_gem_remote_fetcher.rb: leaked FDs

nobu	2014-11-04 16:23:59 +0900 (Tue, 04 Nov 2014)

  New Revision: 48265

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

  Log:
    test_gem_remote_fetcher.rb: leaked FDs
    
    * test/rubygems/test_gem_remote_fetcher.rb (RemoteFetcherCleanup):
      close all pooled connections for each tests to fix leaked file
      descriptors.

  Modified files:
    trunk/ChangeLog
    trunk/test/rubygems/test_gem_remote_fetcher.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48264)
+++ ChangeLog	(revision 48265)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Nov  4 16:23:57 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* test/rubygems/test_gem_remote_fetcher.rb (RemoteFetcherCleanup):
+	  close all pooled connections for each tests to fix leaked file
+	  descriptors.
+
 Tue Nov  4 12:51:31 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/ruby.h (PRIsVALUE), vsnprintf.c (BSD_vfprintf): add
Index: test/rubygems/test_gem_remote_fetcher.rb
===================================================================
--- test/rubygems/test_gem_remote_fetcher.rb	(revision 48264)
+++ test/rubygems/test_gem_remote_fetcher.rb	(revision 48265)
@@ -77,6 +77,30 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L77
 
   DIR = File.expand_path(File.dirname(__FILE__))
 
+  module RemoteFetcherCleanup
+    refine Gem::RemoteFetcher do
+      def close_all
+        @pools.each_value {|pool| pool.close_all}
+      end
+    end
+    refine Gem::Request::ConnectionPools do
+      def close_all
+        @pools.each_value {|pool| pool.close_all}
+      end
+    end
+    refine Gem::Request::HTTPPool do
+      def close_all
+        until @queue.empty?
+          if connection = @queue.pop(true) and connection.started?
+            connection.finish
+          end
+        end
+        @queue.push(nil)
+      end
+    end
+  end
+  using RemoteFetcherCleanup
+
   def setup
     @proxies = %w[http_proxy HTTP_PROXY http_proxy_user HTTP_PROXY_USER http_proxy_pass HTTP_PROXY_PASS no_proxy NO_PROXY]
     @old_proxies = @proxies.map {|k| ENV[k] }
@@ -108,6 +132,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L132
   end
 
   def teardown
+    @fetcher.close_all
     self.class.stop_servers
     super
     Gem.configuration[:http_proxy] = nil
@@ -134,6 +159,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L159
 
   def test_fetch_size_bad_uri
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
 
     e = assert_raises ArgumentError do
       fetcher.fetch_size 'gems.example.com/yaml'
@@ -144,6 +170,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L170
 
   def test_fetch_size_socket_error
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
     def fetcher.request(uri, request_class, last_modified = nil)
       raise SocketError, "tarded"
     end
@@ -172,6 +199,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L199
     dns.expect :getresource, target, [String, Object]
 
     fetch = Gem::RemoteFetcher.new nil, dns
+    @fetcher = fetcher
     assert_equal URI.parse("http://blah.com/foo"), fetch.api_endpoint(uri)
 
     target.verify
@@ -435,6 +463,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L463
 
   def test_fetch_path_gzip
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
 
     def fetcher.fetch_http(uri, mtime, head = nil)
       Gem.gzip 'foo'
@@ -445,6 +474,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L474
 
   def test_fetch_path_gzip_unmodified
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
 
     def fetcher.fetch_http(uri, mtime, head = nil)
       nil
@@ -455,6 +485,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L485
 
   def test_fetch_path_io_error
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
 
     def fetcher.fetch_http(*)
       raise EOFError
@@ -472,6 +503,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L503
 
   def test_fetch_path_socket_error
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
 
     def fetcher.fetch_http(uri, mtime, head = nil)
       raise SocketError
@@ -489,6 +521,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L521
 
   def test_fetch_path_system_call_error
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
 
     def fetcher.fetch_http(uri, mtime = nil, head = nil)
       raise Errno::ECONNREFUSED, 'connect(2)'
@@ -507,6 +540,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L540
 
   def test_fetch_path_unmodified
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
 
     def fetcher.fetch_http(uri, mtime, head = nil)
       nil
@@ -519,6 +553,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L553
     use_ui @ui do
       ENV['http_proxy'] = 'http://fakeurl:12345'
       fetcher = Gem::RemoteFetcher.new :no_proxy
+      @fetcher = fetcher
       assert_data_from_server fetcher.fetch_path(@server_uri)
     end
   end
@@ -527,6 +562,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L562
     use_ui @ui do
       ENV['http_proxy'] = @proxy_uri
       fetcher = Gem::RemoteFetcher.new nil
+      @fetcher = fetcher
       assert_data_from_proxy fetcher.fetch_path(@server_uri)
     end
   end
@@ -535,6 +571,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L571
     use_ui @ui do
       ENV['HTTP_PROXY'] = @proxy_uri
       fetcher = Gem::RemoteFetcher.new nil
+      @fetcher = fetcher
       assert_data_from_proxy fetcher.fetch_path(@server_uri)
     end
   end
@@ -542,12 +579,14 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L579
   def test_implicit_proxy_no_env
     use_ui @ui do
       fetcher = Gem::RemoteFetcher.new nil
+      @fetcher = fetcher
       assert_data_from_server fetcher.fetch_path(@server_uri)
     end
   end
 
   def test_fetch_http
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
     url = 'http://gems.example.com/redirect'
 
     def fetcher.request(uri, request_class, last_modified = nil)
@@ -571,6 +610,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L610
 
   def test_fetch_http_redirects
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
     url = 'http://gems.example.com/redirect'
 
     def fetcher.request(uri, request_class, last_modified = nil)
@@ -589,6 +629,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L629
 
   def test_fetch_s3
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
     url = 's3://testuser:testpass@my-bucket/gems/specs.4.8.gz'
     $fetched_uri = nil
 
@@ -613,6 +654,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L654
 
   def test_fetch_s3_no_creds
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
     url = 's3://my-bucket/gems/specs.4.8.gz'
     e = assert_raises Gem::RemoteFetcher::FetchError do
       fetcher.fetch_s3 URI.parse(url)
@@ -626,6 +668,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L668
       ENV["http_proxy"] = @proxy_uri
       ENV["no_proxy"] = URI::parse(@server_uri).host
       fetcher = Gem::RemoteFetcher.new nil
+      @fetcher = fetcher
       assert_data_from_server fetcher.fetch_path(@server_uri)
     end
   end
@@ -635,12 +678,14 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L678
       ENV["http_proxy"] = @proxy_uri
       ENV["no_proxy"] = "fakeurl.com, #{URI::parse(@server_uri).host}"
       fetcher = Gem::RemoteFetcher.new nil
+      @fetcher = fetcher
       assert_data_from_server fetcher.fetch_path(@server_uri)
     end
   end
 
   def test_request_block
     fetcher = Gem::RemoteFetcher.new nil
+    @fetcher = fetcher
 
     assert_throws :block_called do
       fetcher.request URI('http://example'), Net::HTTP::Get do |req|
@@ -654,6 +699,7 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L699
     use_ui @ui do
       self.class.enable_yaml = false
       fetcher = Gem::RemoteFetcher.new nil
+      @fetcher = fetcher
       assert_error { fetcher.size }
     end
   end
@@ -736,8 +782,10 @@ gems: https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_remote_fetcher.rb#L782
       end
       Gem.configuration = Gem::ConfigFile.new %W[--config-file #{temp_conf}]
     end
-    yield Gem::RemoteFetcher.new
+    fetcher = Gem::RemoteFetcher.new
+    yield fetcher
   ensure
+    fetcher.close_all
     Gem.configuration = nil
   end
 

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

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