diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8998222..657d595 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,8 @@ jobs: strategy: fail-fast: true matrix: - ruby: [ 2.7, "3.0", 3.1, 3.2 ] + ruby: [ 2.7, "3.0", 3.1, 3.2, 3.3 ] + os: [ ubuntu-latest, windows-latest ] steps: - uses: actions/checkout@v3 diff --git a/Gemfile.lock b/Gemfile.lock index 5a0e49c..092348f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - turbo_tests (2.2.1) + turbo_tests (2.2.2) json (~> 2.3) parallel_tests (>= 3.3.0, < 5) rspec (>= 3.10) diff --git a/lib/turbo_tests.rb b/lib/turbo_tests.rb index d90a04b..afb362b 100644 --- a/lib/turbo_tests.rb +++ b/lib/turbo_tests.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true +require "securerandom" require "open3" require "fileutils" require "json" + require "rspec" require "parallel_tests" diff --git a/lib/turbo_tests/json_rows_formatter.rb b/lib/turbo_tests/json_rows_formatter.rb index 5471b7e..d0244ca 100644 --- a/lib/turbo_tests/json_rows_formatter.rb +++ b/lib/turbo_tests/json_rows_formatter.rb @@ -164,7 +164,7 @@ def group_to_json(notification) end def output_row(obj) - output.puts(obj.to_json) + output.puts ENV["RSPEC_FORMATTER_OUTPUT_ID"] + obj.to_json output.flush end end diff --git a/lib/turbo_tests/runner.rb b/lib/turbo_tests/runner.rb index 1a74b76..ce2db9e 100644 --- a/lib/turbo_tests/runner.rb +++ b/lib/turbo_tests/runner.rb @@ -24,7 +24,7 @@ def self.run(opts = {}) seed_used = !opts[:seed].nil? if verbose - STDERR.puts "VERBOSE" + warn "VERBOSE" end reporter = Reporter.from_config(formatters, start_time) @@ -134,19 +134,19 @@ def start_subprocess(env, extra_args, tests, process_id, record_runtime:) if tests.empty? @messages << { type: "exit", - process_id: process_id + process_id: process_id, } else - tmp_filename = "tmp/test-pipes/subprocess-#{process_id}" - - begin - File.mkfifo(tmp_filename) - rescue Errno::EEXIST - end - + env["RSPEC_FORMATTER_OUTPUT_ID"] = SecureRandom.uuid env["RUBYOPT"] = ["-I#{File.expand_path("..", __dir__)}", ENV["RUBYOPT"]].compact.join(" ") env["RSPEC_SILENCE_FILTER_ANNOUNCEMENTS"] = "1" + if ENV["BUNDLE_BIN_PATH"] + command_name = [ENV["BUNDLE_BIN_PATH"], "exec", "rspec"] + else + command_name = "rspec" + end + record_runtime_options = if record_runtime [ @@ -158,23 +158,23 @@ def start_subprocess(env, extra_args, tests, process_id, record_runtime:) end command = [ - "rspec", + *command_name, *extra_args, - "--seed", @seed, + "--seed", rand(0xFFFF).to_s, + "--format", "ParallelTests::RSpec::RuntimeLogger", + "--out", @runtime_log, "--format", "TurboTests::JsonRowsFormatter", - "--out", tmp_filename, *record_runtime_options, - *tests + *tests, ] - command.unshift(ENV["BUNDLE_BIN_PATH"], "exec") if ENV["BUNDLE_BIN_PATH"] if @verbose command_str = [ env.map { |k, v| "#{k}=#{v}" }.join(" "), - command.join(" ") + command.join(" "), ].select { |x| x.size > 0 }.join(" ") - STDERR.puts "Process #{process_id}: #{command_str}" + warn "Process #{process_id}: #{command_str}" end stdin, stdout, stderr, wait_thr = Open3.popen3(env, *command) @@ -182,26 +182,30 @@ def start_subprocess(env, extra_args, tests, process_id, record_runtime:) @threads << Thread.new do - File.open(tmp_filename) do |fd| - fd.each_line do |line| - message = JSON.parse(line, symbolize_names: true) + stdout.each_line do |line| + result = line.split(env["RSPEC_FORMATTER_OUTPUT_ID"]) + + output = result.shift + print(output) unless output.empty? + + message = result.shift + next unless message - message[:process_id] = process_id - @messages << message - end + message = JSON.parse(message, symbolize_names: true) + message[:process_id] = process_id + @messages << message end - @messages << {type: "exit", process_id: process_id} + @messages << { type: "exit", process_id: process_id } end - @threads << start_copy_thread(stdout, STDOUT) @threads << start_copy_thread(stderr, STDERR) - @threads << Thread.new { + @threads << Thread.new do unless wait_thr.value.success? - @messages << {type: "error"} + @messages << { type: "error" } end - } + end wait_thr end diff --git a/lib/turbo_tests/version.rb b/lib/turbo_tests/version.rb index 554f6de..af6fbac 100644 --- a/lib/turbo_tests/version.rb +++ b/lib/turbo_tests/version.rb @@ -1,3 +1,3 @@ module TurboTests - VERSION = "2.2.1" + VERSION = "2.2.2" end