2019-09-02 12:10:33 -04:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
require "puma/configuration"
|
|
|
|
|
|
|
|
class TestLauncher < Minitest::Test
|
|
|
|
def test_dependencies_and_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
|
|
|
|
2019-09-13 12:44:02 -04:00
|
|
|
deps, dirs = launcher.send(:dependencies_and_files_to_require_after_prune)
|
2019-09-02 12:10:33 -04:00
|
|
|
|
|
|
|
assert_equal(1, deps.length)
|
|
|
|
assert_match(%r{^nio4r:[\d.]+$}, deps.first)
|
|
|
|
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
|
|
|
|
|
|
|
|
def test_dependencies_and_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
|
|
|
|
|
|
|
deps, dirs = launcher(conf).send(:dependencies_and_files_to_require_after_prune)
|
2019-09-02 12:10:33 -04:00
|
|
|
|
|
|
|
assert_equal(1, deps.length)
|
|
|
|
assert_match(%r{^nio4r:[\d.]+$}, deps.first)
|
|
|
|
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-09-13 12:44:02 -04:00
|
|
|
launcher.send(:log_thread_status)
|
2019-09-12 05:59:54 -04:00
|
|
|
events.stdout.rewind
|
|
|
|
|
|
|
|
assert_match "Thread TID", events.stdout.read
|
|
|
|
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
|