diff --git a/README.md b/README.md index 0d22dc4..5a27f8f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
Turbo-Tests - +
@@ -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 diff --git a/lib/turbo_tests/cli.rb b/lib/turbo_tests/cli.rb index 52beab2..99ee7b5 100644 --- a/lib/turbo_tests/cli.rb +++ b/lib/turbo_tests/cli.rb @@ -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 @@ -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) } @@ -101,6 +111,8 @@ def run verbose: verbose, fail_fast: fail_fast, count: count, + seed: seed, + print_failed_group: print_failed_group ) if success diff --git a/lib/turbo_tests/reporter.rb b/lib/turbo_tests/reporter.rb index 033ffed..4996dca 100644 --- a/lib/turbo_tests/reporter.rb +++ b/lib/turbo_tests/reporter.rb @@ -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) diff --git a/lib/turbo_tests/runner.rb b/lib/turbo_tests/runner.rb index 31fd36e..9e7b768 100644 --- a/lib/turbo_tests/runner.rb +++ b/lib/turbo_tests/runner.rb @@ -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" @@ -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 @@ -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 @@ -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 @@ -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 @@ -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, @@ -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 diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index b25c2a6..2b2836a 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -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 } @@ -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 @@ -18,6 +21,11 @@ \e[36m# #{fixture}:1:in `'\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" } @@ -25,7 +33,7 @@ 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 @@ -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