From ef7cf3f30c094689eef25e61448eb925292cd84f Mon Sep 17 00:00:00 2001 From: Dmitry Drobotov Date: Tue, 7 Nov 2023 10:41:12 +0000 Subject: [PATCH] Configurable Persistent HTTP Pool --- CONTRIBUTING.md | 3 ++- .../azure/storage/common/core/http_client.rb | 2 +- .../storage/common/service/storage_service.rb | 4 ++-- test/unit/core/http_client_test.rb | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 308276f2..8bb86c82 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,6 +44,7 @@ You can use the following commands to run: * All the tests: ``rake test``. **This will run integration tests if you have .env file or env vars setup** * Run storage suite of tests: ``rake test:unit``, ``rake test:integration`` * One particular test file: ``ruby -I".\blob\lib;.\common\lib;.\table\lib;.\queue\lib;.\file\lib;test" ""`` +* Use ``MT_COMPAT=1 rake test`` environment variable in case you get ``NameError: uninitialized constant MiniTest`` (see https://github.com/minitest/minitest/commit/a2c6c18570f6f0a1bf6af70fe3b6d9599a13fdd6) ### Testing Features As you develop a feature, you'll need to write tests to ensure quality. Your changes should be covered by both unit tests and integration tests. You should also run existing tests related to your change to address any unexpected breaks. @@ -71,4 +72,4 @@ We strive to release each new feature for each of our environments at the same t ### Review Process We expect all guidelines to be met before accepting a pull request. As such, we will work with you to address issues we find by leaving comments in your code. Please understand that it may take a few iterations before the code is accepted as we maintain high standards on code quality. Once we feel comfortable with a contribution, we will validate the change and accept the pull request. -Thank you for any contributions! Please let the team know if you have any questions or concerns about our contribution policy. \ No newline at end of file +Thank you for any contributions! Please let the team know if you have any questions or concerns about our contribution policy. diff --git a/common/lib/azure/storage/common/core/http_client.rb b/common/lib/azure/storage/common/core/http_client.rb index 4fdc06f4..bb5ce626 100644 --- a/common/lib/azure/storage/common/core/http_client.rb +++ b/common/lib/azure/storage/common/core/http_client.rb @@ -72,7 +72,7 @@ def build_http(uri) end || nil Faraday.new(uri, ssl: ssl_options, proxy: proxy_options) do |conn| conn.use FaradayMiddleware::FollowRedirects - conn.adapter :net_http_persistent, pool_size: 5 do |http| + conn.adapter :net_http_persistent, pool_size: ENV.fetch('AZURE_STORAGE_HTTP_POOL', 5).to_i do |http| # yields Net::HTTP::Persistent http.idle_timeout = 100 end diff --git a/common/lib/azure/storage/common/service/storage_service.rb b/common/lib/azure/storage/common/service/storage_service.rb index e223009c..9d81874d 100644 --- a/common/lib/azure/storage/common/service/storage_service.rb +++ b/common/lib/azure/storage/common/service/storage_service.rb @@ -239,8 +239,8 @@ class << self # Registers the callback when sending the request # The headers in the request can be viewed or changed in the code block - def register_request_callback - @request_callback = Proc.new + def register_request_callback(&block) + @request_callback = proc &block end # Get the request location. diff --git a/test/unit/core/http_client_test.rb b/test/unit/core/http_client_test.rb index 1133400d..5c286cfd 100644 --- a/test/unit/core/http_client_test.rb +++ b/test/unit/core/http_client_test.rb @@ -63,5 +63,24 @@ _(Azure::Storage::Common::Client::create.agents(uri).proxy.uri).must_equal https_proxy_uri end end + + describe "when net_http_persistent pool is set" do + let(:pool_size) { 10 } + + before do + ENV["AZURE_STORAGE_HTTP_POOL"] = pool_size.to_s + end + + after do + ENV["AZURE_STORAGE_HTTP_POOL"] = nil + end + + it "should set the pool size for connection" do + agent = Azure::Storage::Common::Client::create.agents(uri) + size = agent.builder.adapter.instance_variable_get(:@args)[0][:pool_size] + + _(size).must_equal pool_size + end + end end end