2019-09-02 12:10:33 -04:00
|
|
|
require_relative "helper"
|
2020-07-12 13:00:29 -04:00
|
|
|
require_relative "helpers/tmp_path"
|
2019-09-02 12:10:33 -04:00
|
|
|
|
|
|
|
require "puma/configuration"
|
2020-04-14 00:06:30 -04:00
|
|
|
require 'puma/events'
|
2019-09-02 12:10:33 -04:00
|
|
|
|
|
|
|
class TestLauncher < Minitest::Test
|
2020-07-12 13:00:29 -04:00
|
|
|
include TmpPath
|
|
|
|
|
2020-10-20 09:31:23 -04:00
|
|
|
def test_files_to_require_after_prune_is_correctly_built_for_no_extra_deps
|
2019-09-13 12:44:02 -04:00
|
|
|
skip_on :no_bundler
|
2019-09-02 12:10:33 -04:00
|
|
|
|
2020-10-20 09:31:23 -04:00
|
|
|
dirs = launcher.send(:files_to_require_after_prune)
|
2019-09-02 12:10:33 -04:00
|
|
|
|
|
|
|
assert_equal(2, dirs.length)
|
|
|
|
assert_match(%r{puma/lib$}, dirs[0]) # lib dir
|
|
|
|
assert_match(%r{puma-#{Puma::Const::PUMA_VERSION}$}, dirs[1]) # native extension dir
|
2019-09-13 12:44:02 -04:00
|
|
|
refute_match(%r{gems/rdoc-[\d.]+/lib$}, dirs[2])
|
2019-09-02 12:10:33 -04:00
|
|
|
end
|
|
|
|
|
2020-10-20 09:31:23 -04:00
|
|
|
def test_files_to_require_after_prune_is_correctly_built_with_extra_deps
|
2019-09-13 12:44:02 -04:00
|
|
|
skip_on :no_bundler
|
2019-09-02 12:10:33 -04:00
|
|
|
conf = Puma::Configuration.new do |c|
|
|
|
|
c.extra_runtime_dependencies ['rdoc']
|
|
|
|
end
|
2019-09-13 12:44:02 -04:00
|
|
|
|
2020-10-20 09:31:23 -04:00
|
|
|
dirs = launcher(conf).send(:files_to_require_after_prune)
|
2019-09-02 12:10:33 -04:00
|
|
|
|
|
|
|
assert_equal(3, dirs.length)
|
|
|
|
assert_match(%r{puma/lib$}, dirs[0]) # lib dir
|
|
|
|
assert_match(%r{puma-#{Puma::Const::PUMA_VERSION}$}, dirs[1]) # native extension dir
|
|
|
|
assert_match(%r{gems/rdoc-[\d.]+/lib$}, dirs[2]) # rdoc dir
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_extra_runtime_deps_directories_is_empty_for_no_config
|
2019-09-13 12:44:02 -04:00
|
|
|
assert_equal([], launcher.send(:extra_runtime_deps_directories))
|
2019-09-02 12:10:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_extra_runtime_deps_directories_is_correctly_built
|
2019-09-13 12:44:02 -04:00
|
|
|
skip_on :no_bundler
|
2019-09-02 12:10:33 -04:00
|
|
|
conf = Puma::Configuration.new do |c|
|
|
|
|
c.extra_runtime_dependencies ['rdoc']
|
|
|
|
end
|
2019-09-13 12:44:02 -04:00
|
|
|
dep_dirs = launcher(conf).send(:extra_runtime_deps_directories)
|
2019-09-02 12:10:33 -04:00
|
|
|
|
|
|
|
assert_equal(1, dep_dirs.length)
|
|
|
|
assert_match(%r{gems/rdoc-[\d.]+/lib$}, dep_dirs.first)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_puma_wild_location_is_an_absolute_path
|
2019-09-13 12:44:02 -04:00
|
|
|
skip_on :no_bundler
|
|
|
|
puma_wild_location = launcher.send(:puma_wild_location)
|
|
|
|
|
2019-09-02 12:10:33 -04:00
|
|
|
assert_match(%r{bin/puma-wild$}, puma_wild_location)
|
|
|
|
# assert no "/../" in path
|
|
|
|
refute_match(%r{/\.\./}, puma_wild_location)
|
|
|
|
end
|
2019-09-12 05:59:54 -04:00
|
|
|
|
|
|
|
def test_prints_thread_traces
|
2019-11-11 00:08:41 -05:00
|
|
|
launcher.thread_status do |name, _backtrace|
|
|
|
|
assert_match "Thread: TID", name
|
|
|
|
end
|
2019-09-12 05:59:54 -04:00
|
|
|
end
|
2019-09-13 12:44:02 -04:00
|
|
|
|
2019-09-20 05:51:57 -04:00
|
|
|
def test_pid_file
|
2020-07-06 08:10:55 -04:00
|
|
|
pid_path = tmp_path('.pid')
|
2019-09-20 05:51:57 -04:00
|
|
|
|
|
|
|
conf = Puma::Configuration.new do |c|
|
2020-07-06 08:10:55 -04:00
|
|
|
c.pidfile pid_path
|
2019-09-20 05:51:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
launcher(conf).write_state
|
|
|
|
|
2020-07-06 08:10:55 -04:00
|
|
|
assert_equal File.read(pid_path).strip.to_i, Process.pid
|
2019-09-20 05:51:57 -04:00
|
|
|
|
2020-07-06 08:10:55 -04:00
|
|
|
File.unlink pid_path
|
2019-09-20 05:51:57 -04:00
|
|
|
end
|
2020-05-06 23:13:35 -04:00
|
|
|
|
|
|
|
def test_state_permission_0640
|
2020-07-06 08:10:55 -04:00
|
|
|
state_path = tmp_path('.state')
|
|
|
|
state_permission = 0640
|
2020-05-06 23:13:35 -04:00
|
|
|
|
|
|
|
conf = Puma::Configuration.new do |c|
|
2020-07-06 08:10:55 -04:00
|
|
|
c.state_path state_path
|
|
|
|
c.state_permission state_permission
|
2020-05-06 23:13:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
launcher(conf).write_state
|
|
|
|
|
2020-07-06 08:10:55 -04:00
|
|
|
assert File.stat(state_path).mode.to_s(8)[-4..-1], state_permission
|
2020-05-06 23:13:35 -04:00
|
|
|
ensure
|
2020-07-06 08:10:55 -04:00
|
|
|
File.unlink state_path
|
2020-05-06 23:13:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_state_permission_nil
|
2020-07-06 08:10:55 -04:00
|
|
|
state_path = tmp_path('.state')
|
2020-05-06 23:13:35 -04:00
|
|
|
|
|
|
|
conf = Puma::Configuration.new do |c|
|
2020-07-06 08:10:55 -04:00
|
|
|
c.state_path state_path
|
2020-05-06 23:13:35 -04:00
|
|
|
c.state_permission nil
|
|
|
|
end
|
|
|
|
|
|
|
|
launcher(conf).write_state
|
|
|
|
|
2020-07-06 08:10:55 -04:00
|
|
|
assert File.exist?(state_path)
|
2020-05-06 23:13:35 -04:00
|
|
|
ensure
|
2020-07-06 08:10:55 -04:00
|
|
|
File.unlink state_path
|
2020-05-06 23:13:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_state_permission
|
2020-07-06 08:10:55 -04:00
|
|
|
state_path = tmp_path('.state')
|
2020-05-06 23:13:35 -04:00
|
|
|
|
|
|
|
conf = Puma::Configuration.new do |c|
|
2020-07-06 08:10:55 -04:00
|
|
|
c.state_path state_path
|
2020-05-06 23:13:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
launcher(conf).write_state
|
|
|
|
|
2020-07-06 08:10:55 -04:00
|
|
|
assert File.exist?(state_path)
|
2020-05-06 23:13:35 -04:00
|
|
|
ensure
|
2020-07-06 08:10:55 -04:00
|
|
|
File.unlink state_path
|
2020-05-06 23:13:35 -04:00
|
|
|
end
|
2019-09-20 05:51:57 -04:00
|
|
|
|
2020-04-14 00:06:30 -04:00
|
|
|
def test_puma_stats
|
|
|
|
conf = Puma::Configuration.new do |c|
|
|
|
|
c.app -> {[200, {}, ['']]}
|
|
|
|
c.clear_binds!
|
|
|
|
end
|
|
|
|
launcher = launcher(conf)
|
2020-10-19 11:22:28 -04:00
|
|
|
launcher.events.on_booted {
|
|
|
|
sleep 1.1 unless Puma.mri?
|
|
|
|
launcher.stop
|
|
|
|
}
|
2020-04-14 00:06:30 -04:00
|
|
|
launcher.run
|
2020-10-19 11:22:28 -04:00
|
|
|
sleep 1 unless Puma.mri?
|
2020-04-14 00:06:30 -04:00
|
|
|
Puma::Server::STAT_METHODS.each do |stat|
|
2020-05-10 21:20:19 -04:00
|
|
|
assert_includes Puma.stats_hash, stat
|
2020-04-14 00:06:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_puma_stats_clustered
|
|
|
|
skip NO_FORK_MSG unless HAS_FORK
|
|
|
|
|
|
|
|
conf = Puma::Configuration.new do |c|
|
|
|
|
c.app -> {[200, {}, ['']]}
|
|
|
|
c.workers 1
|
|
|
|
c.clear_binds!
|
|
|
|
end
|
|
|
|
launcher = launcher(conf)
|
|
|
|
Thread.new do
|
|
|
|
sleep Puma::Const::WORKER_CHECK_INTERVAL + 1
|
2020-05-10 21:20:19 -04:00
|
|
|
status = Puma.stats_hash[:worker_status].first[:last_status]
|
2020-04-14 00:06:30 -04:00
|
|
|
Puma::Server::STAT_METHODS.each do |stat|
|
|
|
|
assert_includes status, stat
|
|
|
|
end
|
|
|
|
launcher.stop
|
|
|
|
end
|
|
|
|
launcher.run
|
|
|
|
end
|
|
|
|
|
2020-11-02 10:32:37 -05:00
|
|
|
def test_log_config_enabled
|
|
|
|
ENV['PUMA_LOG_CONFIG'] = "1"
|
|
|
|
|
|
|
|
assert_match(/Configuration:/, launcher.events.stdout.string)
|
|
|
|
|
|
|
|
launcher.config.final_options.each do |config_key, _value|
|
|
|
|
assert_match(/#{config_key}/, launcher.events.stdout.string)
|
|
|
|
end
|
|
|
|
|
|
|
|
ENV.delete('PUMA_LOG_CONFIG')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_log_config_disabled
|
|
|
|
refute_match /Configuration:/, launcher.events.stdout.string
|
|
|
|
end
|
|
|
|
|
2019-09-13 12:44:02 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def events
|
|
|
|
@events ||= Puma::Events.strings
|
|
|
|
end
|
|
|
|
|
|
|
|
def launcher(config = Puma::Configuration.new, evts = events)
|
|
|
|
@launcher ||= Puma::Launcher.new(config, events: evts)
|
|
|
|
end
|
2019-09-02 12:10:33 -04:00
|
|
|
end
|