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

Add option to print failing group #34

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div align="center">
<img src="https://user-images.githubusercontent.com/78694043/233910064-87a6d557-1120-42d2-b965-2a9403c6f2f4.svg" width="500" alt="Turbo-Tests">

</div>

<div align="center">
Expand Down Expand Up @@ -96,6 +96,8 @@ Options:
--runtime-log FILE Location of previously recorded test runtimes
-v, --verbose More output
--fail-fast=[N]
--seed SEED Seed for rspec
--print_failed_group Prints group that had failures in it
```

## Development
Expand Down
12 changes: 12 additions & 0 deletions lib/turbo_tests/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def run
runtime_log = nil
verbose = false
fail_fast = nil
seed = nil
print_failed_group = false

OptionParser.new { |opts|
opts.banner = <<~BANNER
Expand Down Expand Up @@ -76,6 +78,14 @@ def run
end
fail_fast = n.nil? || n < 1 ? 1 : n
end

opts.on("--seed SEED", "Seed for rspec") do |s|
seed = s
end

opts.on("--print_failed_group", "Prints group that had failures in it") do
print_failed_group = true
end
}.parse!(@argv)

requires.each { |f| require(f) }
Expand All @@ -101,6 +111,8 @@ def run
verbose: verbose,
fail_fast: fail_fast,
count: count,
seed: seed,
print_failed_group: print_failed_group
)

if success
Expand Down
5 changes: 5 additions & 0 deletions lib/turbo_tests/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ def finish
RSpec::Core::Notifications::NullNotification)
end

def seed_notification(seed, seed_used)
puts RSpec::Core::Notifications::SeedNotification.new(seed, seed_used).fully_formatted
puts
end

protected

def delegate_to_formatters(method, *args)
Expand Down
29 changes: 26 additions & 3 deletions lib/turbo_tests/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def self.run(opts = {})
verbose = opts.fetch(:verbose, false)
fail_fast = opts.fetch(:fail_fast, nil)
count = opts.fetch(:count, nil)
seed = opts.fetch(:seed, nil) || rand(0xFFFF).to_s
seed_used = !opts[:seed].nil?
print_failed_group = opts.fetch(:print_failed_group, false)

if verbose
STDERR.puts "VERBOSE"
Expand All @@ -34,7 +37,10 @@ def self.run(opts = {})
runtime_log: runtime_log,
verbose: verbose,
fail_fast: fail_fast,
count: count
count: count,
seed: seed,
seed_used: seed_used,
print_failed_group: print_failed_group
).run
end

Expand All @@ -49,10 +55,12 @@ def initialize(opts)
@load_time = 0
@load_count = 0
@failure_count = 0

@seed = opts[:seed]
@seed_used = opts[:seed_used]
@messages = Thread::Queue.new
@threads = []
@error = false
@print_failed_group = opts[:print_failed_group]
end

def run
Expand Down Expand Up @@ -86,6 +94,8 @@ def run

report_number_of_tests(tests_in_groups)

@reporter.seed_notification(@seed, @seed_used)

wait_threads = tests_in_groups.map.with_index do |tests, process_id|
start_regular_subprocess(tests, process_id + 1, **subprocess_opts)
end
Expand All @@ -94,8 +104,12 @@ def run

@reporter.finish

@reporter.seed_notification(@seed, @seed_used)

@threads.each(&:join)

report_failed_group(wait_threads, tests_in_groups) if @print_failed_group

@reporter.failed_examples.empty? && wait_threads.map(&:value).all?(&:success?)
end

Expand Down Expand Up @@ -150,7 +164,7 @@ def start_subprocess(env, extra_args, tests, process_id, record_runtime:)
command = [
ENV["BUNDLE_BIN_PATH"], "exec", "rspec",
*extra_args,
"--seed", rand(0xFFFF).to_s,
"--seed", @seed,
"--format", "TurboTests::JsonRowsFormatter",
"--out", tmp_filename,
*record_runtime_options,
Expand Down Expand Up @@ -272,5 +286,14 @@ def report_number_of_tests(groups)

puts "#{num_processes} processes for #{num_tests} #{name}s, ~ #{tests_per_process} #{name}s per process"
end

def report_failed_group(wait_threads, tests_in_groups)
wait_threads.map(&:value).each_with_index do |value, index|
next if value.success?

failing_group = tests_in_groups[index].join(" ")
puts "Group that failed: #{failing_group}"
end
end
end
end
14 changes: 11 additions & 3 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RSpec.describe TurboTests::CLI do
subject(:output) { `bundle exec turbo_tests -f d #{fixture}`.strip }
subject(:output) { `bundle exec turbo_tests -f d #{fixture} --seed 1234`.strip }

before { output }

Expand All @@ -8,6 +8,9 @@
%(
1 processes for 1 specs, ~ 1 specs per process

Randomized with seed 1234


An error occurred while loading #{fixture}.
\e[31mFailure/Error: \e[0m\e[1;34m1\e[0m / \e[1;34m0\e[0m\e[0m
\e[31m\e[0m
Expand All @@ -18,14 +21,19 @@
\e[36m# #{fixture}:1:in `<top (required)>'\e[0m
).strip
}
let(:expected_end_of_output) do
"0 examples, 0 failures\n"\
"\n\n"\
"Randomized with seed 1234"
end

let(:fixture) { "./fixtures/rspec/errors_outside_of_examples_spec.rb" }

it "reports" do
expect($?.exitstatus).to eql(1)

expect(output).to start_with(expected_start_of_output)
expect(output).to end_with("0 examples, 0 failures")
expect(output).to end_with(expected_end_of_output)
end
end

Expand Down Expand Up @@ -66,7 +74,7 @@
expect(output).to include(part)
end

expect(output).to end_with("3 examples, 0 failures, 3 pending")
expect(output).to end_with("3 examples, 0 failures, 3 pending\n\n\nRandomized with seed 1234")
end
end

Expand Down