From 6f4142625f1808d6fcc45dcc80ac0bb66f83b7b8 Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Tue, 5 Nov 2024 11:33:39 -0600 Subject: [PATCH] CI: fixup test/test_web_concurrency_auto.rb, add 'concurrent-ruby' to main Gemfile (#3545) --- Gemfile | 1 + test/helpers/integration.rb | 1 + test/test_web_concurrency_auto.rb | 56 ++++++++++++++++++++++------- test/web_concurrency_test/Gemfile | 5 --- test/web_concurrency_test/config.ru | 5 --- 5 files changed, 45 insertions(+), 23 deletions(-) delete mode 100644 test/web_concurrency_test/Gemfile delete mode 100644 test/web_concurrency_test/config.ru diff --git a/Gemfile b/Gemfile index 6dfddf50b0..0bfa58c147 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,7 @@ gem "minitest", "~> 5.11" gem "minitest-retry" gem "minitest-proveit" gem "minitest-stub-const" +gem "concurrent-ruby", "~> 1.3" case ENV['PUMA_CI_RACK']&.strip when 'rack2' diff --git a/test/helpers/integration.rb b/test/helpers/integration.rb index eac9c23d61..fd7cea4189 100644 --- a/test/helpers/integration.rb +++ b/test/helpers/integration.rb @@ -111,6 +111,7 @@ def cli_server(argv, # rubocop:disable Metrics/ParameterLists "#{BASE} #{puma_path} #{config} -b unix://#{@bind_path} #{argv}" else @tcp_port = UniquePort.call + @bind_port = @tcp_port "#{BASE} #{puma_path} #{config} -b tcp://#{HOST}:#{@tcp_port} #{argv}" end diff --git a/test/test_web_concurrency_auto.rb b/test/test_web_concurrency_auto.rb index 1e53330c59..972b64c856 100644 --- a/test/test_web_concurrency_auto.rb +++ b/test/test_web_concurrency_auto.rb @@ -1,8 +1,20 @@ require_relative "helper" require_relative "helpers/integration" +require_relative "helpers/test_puma/puma_socket" + +require "puma/configuration" +require 'puma/log_writer' class TestWebConcurrencyAuto < TestIntegration + include TestPuma::PumaSocket + + ENV_WC_TEST = { + # -W0 removes logging of bundled gem warnings + "RUBYOPT" => "#{ENV["RUBYOPT"]} -W0", + "WEB_CONCURRENCY" => "auto" + } + def teardown return if skipped? super @@ -10,20 +22,38 @@ def teardown def test_web_concurrency_with_concurrent_ruby_available skip_unless :fork - env = { - "BUNDLE_GEMFILE" => "#{__dir__}/web_concurrency_test/Gemfile", - "WEB_CONCURRENCY" => "auto" - } - Dir.chdir("#{__dir__}/web_concurrency_test") do - with_unbundled_env do - silent_and_checked_system_command("bundle config --local path vendor/bundle") - silent_and_checked_system_command("bundle install") - end - cli_server set_pumactl_args, env: env + + app = "app { |_| [200, {}, [Concurrent.available_processor_count.to_i.to_s]] }\n" + + cli_server set_pumactl_args, env: ENV_WC_TEST, config: app + + expected = send_http_read_resp_body GET_11 + assert_equal(expected, get_stats.fetch("workers").to_s) + end + + # Rename the processor_counter file, then restore + def test_web_concurrency_with_concurrent_ruby_unavailable + file_path = nil + skip_unless :fork + + ccr_gem = 'concurrent-ruby' + file_require = 'concurrent/utility/processor_counter' + file_path = Dir["#{ENV['GEM_HOME']}/gems/#{ccr_gem}-*/lib/#{ccr_gem}/#{file_require}.rb"].first + + if file_path && File.exist?(file_path) + File.rename file_path, "#{file_path}_orig" + else + # cannot find concurrent-ruby file? end - connection = connect("/worker_count") - body = read_body(connection, 1) - assert_equal(get_stats.fetch("workers").to_s, body) + out, err = capture_io do + assert_raises(LoadError) { Puma::Configuration.new({}, {}, ENV_WC_TEST) } + end + assert_includes err, 'Please add "concurrent-ruby" to your Gemfile' + + ensure + if file_path && File.exist?("#{file_path}_orig") + File.rename "#{file_path}_orig", file_path + end end end diff --git a/test/web_concurrency_test/Gemfile b/test/web_concurrency_test/Gemfile deleted file mode 100644 index 58f8134b4b..0000000000 --- a/test/web_concurrency_test/Gemfile +++ /dev/null @@ -1,5 +0,0 @@ -source "https://rubygems.org" - -gem 'puma', path: '../..' - -gem 'concurrent-ruby', '~> 1.0' diff --git a/test/web_concurrency_test/config.ru b/test/web_concurrency_test/config.ru deleted file mode 100644 index 79561d6d50..0000000000 --- a/test/web_concurrency_test/config.ru +++ /dev/null @@ -1,5 +0,0 @@ -map "/worker_count" do - run ->(env) { - [200, {}, [Concurrent.available_processor_count.to_i.to_s]] - } -end