Skip to content

Commit 62542cc

Browse files
authored
Merge pull request rails#43558 from Shopify/speedup-railtie-tests
Setup bootsnap to speedup TestRunnerTest
2 parents a93a8f1 + 05887d3 commit 62542cc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

railties/test/isolation/abstract_unit.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def app_template_path
3838
File.join RAILS_FRAMEWORK_ROOT, "tmp/templates/app_template"
3939
end
4040

41+
def bootsnap_cache_path
42+
File.join RAILS_FRAMEWORK_ROOT, "tmp/templates/bootsnap"
43+
end
44+
4145
def tmp_path(*args)
4246
@tmp_path ||= File.realpath(Dir.mktmpdir(nil, File.join(RAILS_FRAMEWORK_ROOT, "tmp")))
4347
File.join(@tmp_path, *args)
@@ -368,7 +372,12 @@ def rails(*args, allow_failure: false, stderr: false)
368372
Process.waitpid pid
369373

370374
else
371-
output = `cd #{app_path}; #{command}`
375+
ENV["BOOTSNAP_CACHE_DIR"] = bootsnap_cache_path
376+
begin
377+
output = `cd #{app_path}; #{command}`
378+
ensure
379+
ENV.delete("BOOTSNAP_CACHE_DIR")
380+
end
372381
end
373382

374383
raise "rails command failed (#{$?.exitstatus}): #{command}\n#{output}" unless allow_failure || $?.success?
@@ -513,6 +522,7 @@ def self.sh(cmd)
513522

514523
sh "#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-bundle --no-rc --quiet"
515524
File.open("#{app_template_path}/config/boot.rb", "w") do |f|
525+
f.puts 'require "bootsnap/setup" if ENV["BOOTSNAP_CACHE_DIR"]'
516526
f.puts 'require "rails/all"'
517527
end
518528

0 commit comments

Comments
 (0)