2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-20 02:11:10 -05:00
|
|
|
require "isolation/abstract_unit"
|
2017-08-19 01:38:31 -04:00
|
|
|
require "console_helpers"
|
2017-01-20 02:11:10 -05:00
|
|
|
require "rails/command"
|
|
|
|
require "rails/commands/server/server_command"
|
|
|
|
|
|
|
|
module ApplicationTests
|
|
|
|
class ServerTest < ActiveSupport::TestCase
|
|
|
|
include ActiveSupport::Testing::Isolation
|
2017-08-19 01:38:31 -04:00
|
|
|
include ConsoleHelpers
|
2017-01-20 02:11:10 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
2017-08-19 01:38:31 -04:00
|
|
|
test "restart rails server with custom pid file path" do
|
|
|
|
skip "PTY unavailable" unless available_pty?
|
|
|
|
|
2017-12-24 16:25:10 -05:00
|
|
|
File.open("#{app_path}/config/boot.rb", "w") do |f|
|
2018-05-21 08:04:01 -04:00
|
|
|
f.puts "ENV['BUNDLE_GEMFILE'] = '#{Bundler.default_gemfile}'"
|
2017-12-24 16:25:10 -05:00
|
|
|
f.puts "require 'bundler/setup'"
|
|
|
|
end
|
|
|
|
|
2018-09-10 16:29:43 -04:00
|
|
|
primary, replica = PTY.open
|
2017-08-19 01:38:31 -04:00
|
|
|
pid = nil
|
|
|
|
|
|
|
|
begin
|
2018-09-10 16:29:43 -04:00
|
|
|
pid = Process.spawn("#{app_path}/bin/rails server -P tmp/dummy.pid", in: replica, out: replica, err: replica)
|
|
|
|
assert_output("Listening", primary)
|
2017-08-19 01:38:31 -04:00
|
|
|
|
2017-09-14 05:28:57 -04:00
|
|
|
rails("restart")
|
2017-08-19 01:38:31 -04:00
|
|
|
|
2018-09-10 16:29:43 -04:00
|
|
|
assert_output("Restarting", primary)
|
|
|
|
assert_output("Inherited", primary)
|
2017-08-19 01:38:31 -04:00
|
|
|
ensure
|
|
|
|
kill(pid) if pid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def kill(pid)
|
|
|
|
Process.kill("TERM", pid)
|
|
|
|
Process.wait(pid)
|
|
|
|
rescue Errno::ESRCH
|
|
|
|
end
|
2017-01-20 02:11:10 -05:00
|
|
|
end
|
|
|
|
end
|