Skip to content

Commit 6e9be6f

Browse files
Sort runtime_logger output (grosser#924)
* Sort `runtime_logger` output Show the slowest tests first * Update changelog and contributor * Delete .devcontainer/devcontainer.json
1 parent 8a663bd commit 6e9be6f

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Sort the output of `runtime_logger` for RSpec to show slowest tests first
6+
57
### Breaking Changes
68

79
### Added

lib/parallel_tests/rspec/runtime_logger.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def dump_pending(*); end
3636
def start_dump(*)
3737
return unless ENV['TEST_ENV_NUMBER'] # only record when running in parallel
3838
lock_output do
39+
# Order the output from slowest to fastest
40+
@example_times = @example_times.sort_by(&:last).reverse
3941
@example_times.each do |file, time|
4042
relative_path = file.sub(%r{^#{Regexp.escape Dir.pwd}/}, '').sub(%r{^\./}, "")
4143
@output.puts "#{relative_path}:#{[time, 0].max}"

spec/parallel_tests/rspec/runtime_logger_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,22 @@ def write(file, content)
120120
end
121121
RUBY
122122

123+
write "spec/slower_spec.rb", <<-RUBY
124+
describe "xxx" do
125+
it "is slow" do
126+
sleep 3
127+
end
128+
end
129+
RUBY
130+
123131
system(
124132
{ 'TEST_ENV_NUMBER' => '1' },
125133
"rspec", "spec", "-I", Bundler.root.join("lib").to_s, "--format", "ParallelTests::RSpec::RuntimeLogger", "--out", "runtime.log"
126134
) || raise("nope")
127135

128136
result = File.read("runtime.log")
129-
expect(result).to include "a_spec.rb:1.5"
137+
expect(result).to start_with("spec/slower_spec.rb:3.0")
138+
expect(result).to include "spec/a_spec.rb:1.5"
130139
end
131140
end
132141
end

0 commit comments

Comments
 (0)