DEV: Fix bin/turbo_rspec runtime recording (#20407)

This commit 57caf08e13 broke
`bin/turbo_rspec` timing recording via `TurboTests::Runner`,
because we changed to using all `spec/*` folders except
`spec/system` as default for the runner, rather than
the old `['spec']` array, which is what `TurboTests::Runner`
was relying on to determine whether to record test run
time with `ParallelTests::RSpec::RuntimeLogger`.

Instead, we can just pass a new `use_runtime_info` boolean to the
runner class and use it when running against the default set of
spec files using `bin/turbo_rspec` and the turbo rspec rake task.
This commit is contained in:
Martin Brennan 2023-02-23 07:47:11 +10:00 committed by GitHub
parent 1a0174b38d
commit 4ab1f76499
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 53 deletions

View File

@ -1,70 +1,56 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true # frozen_string_literal: true
ENV['RAILS_ENV'] ||= 'test' ENV["RAILS_ENV"] ||= "test"
require './lib/turbo_tests' require "./lib/turbo_tests"
require 'optparse' require "optparse"
requires = [] requires = []
formatters = [] formatters = []
verbose = false verbose = false
fail_fast = nil fail_fast = nil
OptionParser.new do |opts| OptionParser
opts.on("-r", "--require PATH", "Require a file.") do |filename| .new do |opts|
requires << filename opts.on("-r", "--require PATH", "Require a file.") { |filename| requires << filename }
end
opts.on("-f", "--format FORMATTER", "Choose a formatter.") do |name| opts.on("-f", "--format FORMATTER", "Choose a formatter.") do |name|
formatters << { formatters << { name: name, outputs: [] }
name: name,
outputs: []
}
end end
opts.on("-o", "--out FILE", "Write output to a file instead of $stdout") do |filename| opts.on("-o", "--out FILE", "Write output to a file instead of $stdout") do |filename|
if formatters.empty? formatters << { name: "progress", outputs: [] } if formatters.empty?
formatters << {
name: "progress",
outputs: []
}
end
formatters.last[:outputs] << filename formatters.last[:outputs] << filename
end end
opts.on("-v", "--verbose", "More output") do opts.on("-v", "--verbose", "More output") { verbose = true }
verbose = true
end
opts.on("--fail-fast=[N]") do |n| opts.on("--fail-fast=[N]") do |n|
n = Integer(n) rescue nil n =
begin
Integer(n)
rescue StandardError
nil
end
fail_fast = (n.nil? || n < 1) ? 1 : n fail_fast = (n.nil? || n < 1) ? 1 : n
end end
end
end.parse!(ARGV) .parse!(ARGV)
requires.each { |f| require(f) } requires.each { |f| require(f) }
if formatters.empty? formatters << { name: "progress", outputs: [] } if formatters.empty?
formatters << {
name: "progress",
outputs: []
}
end
formatters.each do |formatter| formatters.each { |formatter| formatter[:outputs] << "-" if formatter[:outputs].empty? }
if formatter[:outputs].empty?
formatter[:outputs] << '-'
end
end
# We do not want to include system specs by default, they are super if ARGV.empty?
# slow and require a selenium server to be running. files = TurboTests::Runner.default_spec_folders
default_spec_dirs = Dir.entries("#{Rails.root}/spec").reject do |entry| use_runtime_info = true
!File.directory?("spec/#{entry}") || ["..", ".", "system"].include?(entry) else
end.map { |entry| "spec/#{entry}" } files = ARGV
files = ARGV.empty? ? default_spec_dirs : ARGV use_runtime_info = false
end
puts "Running turbo_rspec using files in #{files}" puts "Running turbo_rspec using files in #{files}"
success = success =
@ -72,7 +58,8 @@ success =
formatters: formatters, formatters: formatters,
files: files, files: files,
verbose: verbose, verbose: verbose,
fail_fast: fail_fast fail_fast: fail_fast,
use_runtime_info: use_runtime_info,
) )
if success if success

View File

@ -3,5 +3,9 @@
task "turbo:spec" => :test do |t| task "turbo:spec" => :test do |t|
require "./lib/turbo_tests" require "./lib/turbo_tests"
TurboTests::Runner.run(formatters: [{ name: "progress", outputs: ["-"] }], files: ["spec"]) TurboTests::Runner.run(
formatters: [{ name: "progress", outputs: ["-"] }],
files: TurboTests::Runner.default_spec_folders,
use_runtime_info: true,
)
end end

View File

@ -8,12 +8,27 @@ module TurboTests
start_time = opts.fetch(:start_time) { Time.now } start_time = opts.fetch(:start_time) { Time.now }
verbose = opts.fetch(:verbose, false) verbose = opts.fetch(:verbose, false)
fail_fast = opts.fetch(:fail_fast, nil) fail_fast = opts.fetch(:fail_fast, nil)
use_runtime_info = opts.fetch(:use_runtime_info, false)
STDERR.puts "VERBOSE" if verbose STDERR.puts "VERBOSE" if verbose
reporter = Reporter.from_config(formatters, start_time) reporter = Reporter.from_config(formatters, start_time)
new(reporter: reporter, files: files, verbose: verbose, fail_fast: fail_fast).run new(
reporter: reporter,
files: files,
verbose: verbose,
fail_fast: fail_fast,
use_runtime_info: use_runtime_info,
).run
end
def self.default_spec_folders
# We do not want to include system specs by default, they are quite slow.
Dir
.entries("#{Rails.root}/spec")
.reject { |entry| !File.directory?("spec/#{entry}") || %w[.. . system].include?(entry) }
.map { |entry| "spec/#{entry}" }
end end
def initialize(opts) def initialize(opts)
@ -21,6 +36,7 @@ module TurboTests
@files = opts[:files] @files = opts[:files]
@verbose = opts[:verbose] @verbose = opts[:verbose]
@fail_fast = opts[:fail_fast] @fail_fast = opts[:fail_fast]
@use_runtime_info = opts[:use_runtime_info]
@failure_count = 0 @failure_count = 0
@messages = Queue.new @messages = Queue.new
@ -32,11 +48,10 @@ module TurboTests
check_for_migrations check_for_migrations
@num_processes = ParallelTests.determine_number_of_processes(nil) @num_processes = ParallelTests.determine_number_of_processes(nil)
use_runtime_info = @files == ["spec"]
group_opts = {} group_opts = {}
if use_runtime_info if @use_runtime_info
group_opts[:runtime_log] = "tmp/turbo_rspec_runtime.log" group_opts[:runtime_log] = "tmp/turbo_rspec_runtime.log"
else else
group_opts[:group_by] = :filesize group_opts[:group_by] = :filesize
@ -47,7 +62,7 @@ module TurboTests
setup_tmp_dir setup_tmp_dir
subprocess_opts = { record_runtime: use_runtime_info } subprocess_opts = { record_runtime: @use_runtime_info }
start_multisite_subprocess(@files, **subprocess_opts) start_multisite_subprocess(@files, **subprocess_opts)