Skip to content

Commit

Permalink
CI: fixup test/test_web_concurrency_auto.rb, add 'concurrent-ruby' to…
Browse files Browse the repository at this point in the history
… main Gemfile (puma#3545)
  • Loading branch information
MSP-Greg authored Nov 5, 2024
1 parent 4c55a1a commit 6f41426
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions test/helpers/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
56 changes: 43 additions & 13 deletions test/test_web_concurrency_auto.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,59 @@
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
end

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
5 changes: 0 additions & 5 deletions test/web_concurrency_test/Gemfile

This file was deleted.

5 changes: 0 additions & 5 deletions test/web_concurrency_test/config.ru

This file was deleted.

0 comments on commit 6f41426

Please sign in to comment.