Skip to content

Commit

Permalink
Sort runtime_logger output (#924)
Browse files Browse the repository at this point in the history
* Sort `runtime_logger` output

Show the slowest tests first

* Update changelog and contributor

* Delete .devcontainer/devcontainer.json
  • Loading branch information
lawrencegripper committed Nov 3, 2023
1 parent 8a663bd commit 6e9be6f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
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
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
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

0 comments on commit 6e9be6f

Please sign in to comment.