mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Setup bootsnap to speedup TestRunnerTest
When running `rails t` we skip the "fork" optimization. Because of this Rails is loaded from scratch. However the vast majority of the code is Rails and other gems so it's the same for all tests. By seting up bootsnap we can dramatically speed it up. main: ``` $ bin/test test/application/test_runner_test.rb -n test_run_single_file Run options: -n test_run_single_file --seed 8478 . Finished in 7.313216s, 0.1367 runs/s, 0.2735 assertions/s. ``` This branch: ``` $ bin/test test/application/test_runner_test.rb -n test_run_single_file Run options: -n test_run_single_file --seed 60063 . Finished in 2.751576s, 0.3634 runs/s, 0.7269 assertions/s. 1 runs, 2 assertions, 0 failures, 0 errors, 0 skips ```
This commit is contained in:
parent
a93a8f1a56
commit
05887d31f1
1 changed files with 11 additions and 1 deletions
|
@ -38,6 +38,10 @@ module TestHelpers
|
|||
File.join RAILS_FRAMEWORK_ROOT, "tmp/templates/app_template"
|
||||
end
|
||||
|
||||
def bootsnap_cache_path
|
||||
File.join RAILS_FRAMEWORK_ROOT, "tmp/templates/bootsnap"
|
||||
end
|
||||
|
||||
def tmp_path(*args)
|
||||
@tmp_path ||= File.realpath(Dir.mktmpdir(nil, File.join(RAILS_FRAMEWORK_ROOT, "tmp")))
|
||||
File.join(@tmp_path, *args)
|
||||
|
@ -368,7 +372,12 @@ module TestHelpers
|
|||
Process.waitpid pid
|
||||
|
||||
else
|
||||
ENV["BOOTSNAP_CACHE_DIR"] = bootsnap_cache_path
|
||||
begin
|
||||
output = `cd #{app_path}; #{command}`
|
||||
ensure
|
||||
ENV.delete("BOOTSNAP_CACHE_DIR")
|
||||
end
|
||||
end
|
||||
|
||||
raise "rails command failed (#{$?.exitstatus}): #{command}\n#{output}" unless allow_failure || $?.success?
|
||||
|
@ -513,6 +522,7 @@ Module.new do
|
|||
|
||||
sh "#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-bundle --no-rc --quiet"
|
||||
File.open("#{app_template_path}/config/boot.rb", "w") do |f|
|
||||
f.puts 'require "bootsnap/setup" if ENV["BOOTSNAP_CACHE_DIR"]'
|
||||
f.puts 'require "rails/all"'
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue