790c9c5f40
This commit addresses the following failures at Rails Nightly CI with assertion enabled Ruby. that has been built with `cppflags="-DENABLE_PATH_CHECK=0 -DRUBY_DEBUG=1" optflags="-O3 -fno-inline"` https://buildkite.com/rails/rails-nightly/builds/191#018dc3d1-9032-4baa-ae8a-3c630889ab5f/1342-1348 https://buildkite.com/rails/rails-nightly/builds/191#018dc3d1-9033-4c0c-b61c-00f26d3a63fb/1198-1204 Related to #51140 - Failures fixed by this commit: ``` $ ruby -v ruby 3.4.0dev (2024-02-20T11:52:09Z master c22cb960cf) [x86_64-linux] $ bin/test test/application/console_test.rb -n test_sandbox Run options: -n test_sandbox --seed 3666 F Failure: FullStackConsoleTest#test_sandbox [test/console_helpers.rb:19]: "=> 0" expected, but got: app-template(dev)> quapp-template(dev)> quiapp-template(dev)> quit. Expected "\r\napp-template(dev)> quapp-template(dev)> quiapp-template(dev)> quit" to include "=> 0". bin/test test/application/console_test.rb:142 Finished in 32.180314s, 0.0311 runs/s, 0.7458 assertions/s. 1 runs, 24 assertions, 1 failures, 0 errors, 0 skips $ ``` ``` $ bin/test test/application/server_test.rb Run options: --seed 64559 F Failure: ApplicationTests::ServerTest#test_restart_rails_server_with_custom_pid_file_path [test/console_helpers.rb:19]: "Listening" expected, but got: . Expected "" to include "Listening". bin/test test/application/server_test.rb:19 F Failure: ApplicationTests::ServerTest#test_run_+server+_blocks_after_the_server_starts [test/console_helpers.rb:19]: "Hello world" expected, but got: . Expected "" to include "Hello world". bin/test test/application/server_test.rb:43 Finished in 2.117413s, 0.9445 runs/s, 1.8891 assertions/s. 2 runs, 4 assertions, 2 failures, 0 errors, 0 skips $ ``` Note: These failures depend on assert_timeout and test environment. If these failures do not reproduce locally, setting short timeout = 1 should reproduce them. ``` $ git diff diff --git a/railties/test/console_helpers.rb b/railties/test/console_helpers.rb index 10d3a54602..32d333ed99 100644 --- a/railties/test/console_helpers.rb +++ b/railties/test/console_helpers.rb @@ -6,7 +6,7 @@ end module ConsoleHelpers - def assert_output(expected, io, timeout = 10) + def assert_output(expected, io, timeout = 1) timeout = Time.now + timeout output = +"" $ ```
77 lines
1.9 KiB
Ruby
77 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "isolation/abstract_unit"
|
|
require "console_helpers"
|
|
require "rails/command"
|
|
|
|
module ApplicationTests
|
|
class ServerTest < ActiveSupport::TestCase
|
|
include ConsoleHelpers
|
|
|
|
def setup
|
|
build_app
|
|
end
|
|
|
|
def teardown
|
|
teardown_app
|
|
end
|
|
|
|
test "restart rails server with custom pid file path" do
|
|
skip "PTY unavailable" unless available_pty?
|
|
|
|
File.open("#{app_path}/config/boot.rb", "w") do |f|
|
|
f.puts "ENV['BUNDLE_GEMFILE'] = '#{Bundler.default_gemfile}'"
|
|
f.puts 'require "bundler/setup"'
|
|
end
|
|
|
|
primary, replica = PTY.open
|
|
pid = nil
|
|
|
|
Bundler.with_original_env do
|
|
pid = Process.spawn("bin/rails server -b localhost -P tmp/dummy.pid", chdir: app_path, in: replica, out: replica, err: replica)
|
|
assert_output("Listening", primary, 100)
|
|
|
|
rails("restart")
|
|
|
|
assert_output("Restarting", primary, 100)
|
|
assert_output("Listening", primary, 100)
|
|
ensure
|
|
kill(pid) if pid
|
|
end
|
|
end
|
|
|
|
test "run +server+ blocks after the server starts" do
|
|
skip "PTY unavailable" unless available_pty?
|
|
|
|
File.open("#{app_path}/config/boot.rb", "w") do |f|
|
|
f.puts "ENV['BUNDLE_GEMFILE'] = '#{Bundler.default_gemfile}'"
|
|
f.puts 'require "bundler/setup"'
|
|
end
|
|
|
|
add_to_config(<<~CODE)
|
|
server do
|
|
puts 'Hello world'
|
|
end
|
|
CODE
|
|
|
|
primary, replica = PTY.open
|
|
pid = nil
|
|
|
|
Bundler.with_original_env do
|
|
pid = Process.spawn("bin/rails server -b localhost", chdir: app_path, in: replica, out: primary, err: replica)
|
|
assert_output("Hello world", primary, 100)
|
|
assert_output("Listening", primary, 100)
|
|
ensure
|
|
kill(pid) if pid
|
|
end
|
|
end
|
|
|
|
private
|
|
def kill(pid)
|
|
Process.kill("TERM", pid)
|
|
Process.wait(pid)
|
|
rescue Errno::ESRCH
|
|
end
|
|
end
|
|
end
|