Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort runtime_logger output #924

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Sort the output of `runtime_logger` for RSpec to show slowest tests first

### Breaking Changes

### Added
Expand Down
2 changes: 2 additions & 0 deletions lib/parallel_tests/rspec/runtime_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def dump_pending(*); end
def start_dump(*)
return unless ENV['TEST_ENV_NUMBER'] # only record when running in parallel
lock_output do
# Order the output from slowest to fastest
@example_times = @example_times.sort_by(&:last).reverse
@example_times.each do |file, time|
relative_path = file.sub(%r{^#{Regexp.escape Dir.pwd}/}, '').sub(%r{^\./}, "")
@output.puts "#{relative_path}:#{[time, 0].max}"
Expand Down
11 changes: 10 additions & 1 deletion spec/parallel_tests/rspec/runtime_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,22 @@ def write(file, content)
end
RUBY

write "spec/slower_spec.rb", <<-RUBY
describe "xxx" do
it "is slow" do
sleep 3
end
end
RUBY

system(
{ 'TEST_ENV_NUMBER' => '1' },
"rspec", "spec", "-I", Bundler.root.join("lib").to_s, "--format", "ParallelTests::RSpec::RuntimeLogger", "--out", "runtime.log"
) || raise("nope")

result = File.read("runtime.log")
expect(result).to include "a_spec.rb:1.5"
expect(result).to start_with("spec/slower_spec.rb:3.0")
expect(result).to include "spec/a_spec.rb:1.5"
end
end
end