aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-08-19 14:38:31 +0900
committeryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-08-21 05:44:11 +0900
commit2904ee23bfc1a442b801f0d35e8e49d51a6d47b6 (patch)
tree47e934d8c73aa67ac13ae7e7a6440716d740f73d /railties/test
parent99c604f1f9de2f2a6fc3d0aec4f274cb05b48c69 (diff)
downloadrails-2904ee23bfc1a442b801f0d35e8e49d51a6d47b6.tar.gz
rails-2904ee23bfc1a442b801f0d35e8e49d51a6d47b6.tar.bz2
rails-2904ee23bfc1a442b801f0d35e8e49d51a6d47b6.zip
Make `restart` and `dev:cache` tasks work when customizing pid file path
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
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/rake/dev_test.rb12
-rw-r--r--railties/test/application/rake/restart_test.rb9
-rw-r--r--railties/test/application/server_test.rb28
-rw-r--r--railties/test/commands/server_test.rb2
4 files changed, 37 insertions, 14 deletions
diff --git a/railties/test/application/rake/dev_test.rb b/railties/test/application/rake/dev_test.rb
index d56f315455..b25593ee1c 100644
--- a/railties/test/application/rake/dev_test.rb
+++ b/railties/test/application/rake/dev_test.rb
@@ -32,12 +32,16 @@ module ApplicationTests
end
end
- test "dev:cache removes server.pid also" do
+ test "dev:cache touches tmp/restart.txt" do
Dir.chdir(app_path) do
- FileUtils.mkdir_p("tmp/pids")
- FileUtils.touch("tmp/pids/server.pid")
`rails dev:cache`
- assert_not File.exist?("tmp/pids/server.pid")
+ assert File.exist?("tmp/restart.txt")
+
+ prev_mtime = File.mtime("tmp/restart.txt")
+ sleep(1)
+ `rails dev:cache`
+ curr_mtime = File.mtime("tmp/restart.txt")
+ assert_not_equal prev_mtime, curr_mtime
end
end
end
diff --git a/railties/test/application/rake/restart_test.rb b/railties/test/application/rake/restart_test.rb
index bf06f4c522..ed96dcb6b1 100644
--- a/railties/test/application/rake/restart_test.rb
+++ b/railties/test/application/rake/restart_test.rb
@@ -35,15 +35,6 @@ module ApplicationTests
assert File.exist?("tmp/restart.txt")
end
end
-
- test "rails restart removes server.pid also" do
- Dir.chdir(app_path) do
- FileUtils.mkdir_p("tmp/pids")
- FileUtils.touch("tmp/pids/server.pid")
- `bin/rails restart`
- assert_not File.exist?("tmp/pids/server.pid")
- end
- end
end
end
end
diff --git a/railties/test/application/server_test.rb b/railties/test/application/server_test.rb
index 97b3b4f6b3..6db9a3b9e8 100644
--- a/railties/test/application/server_test.rb
+++ b/railties/test/application/server_test.rb
@@ -1,12 +1,14 @@
# 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
@@ -29,5 +31,31 @@ module ApplicationTests
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
diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb
index eb739db9d1..556c2289e7 100644
--- a/railties/test/commands/server_test.rb
+++ b/railties/test/commands/server_test.rb
@@ -190,7 +190,7 @@ class Rails::ServerTest < ActiveSupport::TestCase
ARGV.replace args
options = parse_arguments(args)
- expected = "bin/rails server -p 4567 -b 127.0.0.1 -c dummy_config.ru -d -e test -P tmp/server.pid -C"
+ expected = "bin/rails server -p 4567 -b 127.0.0.1 -c dummy_config.ru -d -e test -P tmp/server.pid -C --restart"
assert_equal expected, options[:restart_cmd]
ensure