mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
2904ee23bf
Originally, it hard-coded pid file path. It can not be removed when customizing pid file path. But rake task can not get pid file path. Therefore, do not remove file in rake task, makes it possible to judge whether it is restart from the argument of the command and removes the file in server command. Fixes #29306
61 lines
1.5 KiB
Ruby
61 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "isolation/abstract_unit"
|
|
require "console_helpers"
|
|
require "rails/command"
|
|
require "rails/commands/server/server_command"
|
|
|
|
module ApplicationTests
|
|
class ServerTest < ActiveSupport::TestCase
|
|
include ActiveSupport::Testing::Isolation
|
|
include ConsoleHelpers
|
|
|
|
def setup
|
|
build_app
|
|
end
|
|
|
|
def teardown
|
|
teardown_app
|
|
end
|
|
|
|
test "deprecate support of older `config.ru`" do
|
|
remove_file "config.ru"
|
|
app_file "config.ru", <<-RUBY
|
|
require_relative 'config/environment'
|
|
run AppTemplate::Application
|
|
RUBY
|
|
|
|
server = Rails::Server.new(config: "#{app_path}/config.ru")
|
|
server.app
|
|
|
|
log = File.read(Rails.application.config.paths["log"].first)
|
|
assert_match(/DEPRECATION WARNING: Use `Rails::Application` subclass to start the server is deprecated/, log)
|
|
end
|
|
|
|
test "restart rails server with custom pid file path" do
|
|
skip "PTY unavailable" unless available_pty?
|
|
|
|
master, slave = PTY.open
|
|
pid = nil
|
|
|
|
begin
|
|
pid = Process.spawn("#{app_path}/bin/rails server -P tmp/dummy.pid", in: slave, out: slave, err: slave)
|
|
assert_output("Listening", master)
|
|
|
|
Dir.chdir(app_path) { system("bin/rails restart") }
|
|
|
|
assert_output("Restarting", master)
|
|
assert_output("Inherited", master)
|
|
ensure
|
|
kill(pid) if pid
|
|
end
|
|
end
|
|
|
|
private
|
|
def kill(pid)
|
|
Process.kill("TERM", pid)
|
|
Process.wait(pid)
|
|
rescue Errno::ESRCH
|
|
end
|
|
end
|
|
end
|