From d0246f2be7f7fa9f421aab429261a0dfbe994ea5 Mon Sep 17 00:00:00 2001 From: David Rodriguez Date: Fri, 5 Apr 2024 17:12:37 +0200 Subject: [PATCH 1/5] Test on Windows --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8998222..f1ab088 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,6 +14,7 @@ jobs: fail-fast: true matrix: ruby: [ 2.7, "3.0", 3.1, 3.2 ] + os: [ ubuntu-latest, windows-latest ] steps: - uses: actions/checkout@v3 From 3b70426f02eab9693a94c6e43630ca17cc33f2d6 Mon Sep 17 00:00:00 2001 From: David Rodriguez Date: Fri, 5 Apr 2024 17:14:49 +0200 Subject: [PATCH 2/5] Stream RubyGems patch to make Windows work --- lib/turbo_tests.rb | 2 + lib/turbo_tests/windows.rb | 75 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 lib/turbo_tests/windows.rb diff --git a/lib/turbo_tests.rb b/lib/turbo_tests.rb index d90a04b..8963049 100644 --- a/lib/turbo_tests.rb +++ b/lib/turbo_tests.rb @@ -81,3 +81,5 @@ def notification end end end + +require "turbo_tests/windows" if RUBY_PLATFORM.match?(/mingw|mswin/) diff --git a/lib/turbo_tests/windows.rb b/lib/turbo_tests/windows.rb new file mode 100644 index 0000000..76a8def --- /dev/null +++ b/lib/turbo_tests/windows.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +module TurboTests + class Runner + private + + def start_subprocess(env, extra_args, tests, process_id, record_runtime:) + if tests.empty? + @messages << { + type: "exit", + process_id: process_id, + } + else + require "securerandom" + env["RSPEC_FORMATTER_OUTPUT_ID"] = SecureRandom.uuid + env["RUBYOPT"] = ["-I#{File.expand_path("..", __dir__)}", ENV["RUBYOPT"]].compact.join(" ") + + command_name = Gem.win_platform? ? [Gem.ruby, "bin/rspec"] : "bin/rspec" + + command = [ + *command_name, + *extra_args, + "--seed", rand(0xFFFF).to_s, + "--format", "ParallelTests::RSpec::RuntimeLogger", + "--out", @runtime_log, + "--require", File.expand_path("windows_json_rows_formatter", __dir__), + "--format", "TurboTests::WindowsJsonRowsFormatter", + *tests + ] + + if @verbose + command_str = [ + env.map {|k, v| "#{k}=#{v}" }.join(" "), + command.join(" "), + ].select {|x| x.size > 0 }.join(" ") + + warn "Process #{process_id}: #{command_str}" + end + + stdin, stdout, stderr, wait_thr = Open3.popen3(env, *command) + stdin.close + + @threads << + Thread.new do + require "json" + 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 = JSON.parse(message, symbolize_names: true) + message[:process_id] = process_id + @messages << message + end + + @messages << { type: "exit", process_id: process_id } + end + + @threads << start_copy_thread(stderr, STDERR) + + @threads << Thread.new do + unless wait_thr.value.success? + @messages << { type: "error" } + end + end + + wait_thr + end + end + end +end From df946e75b8c4878b64382d7bce054a8f40013f8f Mon Sep 17 00:00:00 2001 From: David Rodriguez Date: Fri, 5 Apr 2024 17:30:49 +0200 Subject: [PATCH 3/5] Test with Ruby 3.3 too --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f1ab088..657d595 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,7 @@ 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: From b4ad8f4f6fdf4174d41cb835a858a7b446521e55 Mon Sep 17 00:00:00 2001 From: ilyazub Date: Wed, 10 Apr 2024 15:24:00 +0200 Subject: [PATCH 4/5] Output `JsonRowsFormatter` to subprocess' STDOUT instead of using `File.mkfifo` Related to https://github.com/serpapi/turbo_tests/issues/38#issuecomment-1740685566 --- Gemfile.lock | 4 ++ lib/turbo_tests.rb | 4 +- lib/turbo_tests/json_rows_formatter.rb | 2 +- lib/turbo_tests/runner.rb | 58 ++++++++++---------- lib/turbo_tests/windows.rb | 75 -------------------------- turbo_tests.gemspec | 2 + 6 files changed, 40 insertions(+), 105 deletions(-) delete mode 100644 lib/turbo_tests/windows.rb diff --git a/Gemfile.lock b/Gemfile.lock index 4657e0d..105b46b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,8 @@ PATH remote: . specs: turbo_tests (2.2.0) + fileutils (~> 1.4) + open3 (~> 0.1) parallel_tests (>= 3.3.0, < 5) rspec (>= 3.10) @@ -10,7 +12,9 @@ GEM specs: coderay (1.1.3) diff-lcs (1.5.0) + fileutils (1.7.2) method_source (1.0.0) + open3 (0.2.1) parallel (1.22.1) parallel_tests (4.2.0) parallel diff --git a/lib/turbo_tests.rb b/lib/turbo_tests.rb index 8963049..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" @@ -81,5 +83,3 @@ def notification end end end - -require "turbo_tests/windows" if RUBY_PLATFORM.match?(/mingw|mswin/) 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/windows.rb b/lib/turbo_tests/windows.rb deleted file mode 100644 index 76a8def..0000000 --- a/lib/turbo_tests/windows.rb +++ /dev/null @@ -1,75 +0,0 @@ -# frozen_string_literal: true - -module TurboTests - class Runner - private - - def start_subprocess(env, extra_args, tests, process_id, record_runtime:) - if tests.empty? - @messages << { - type: "exit", - process_id: process_id, - } - else - require "securerandom" - env["RSPEC_FORMATTER_OUTPUT_ID"] = SecureRandom.uuid - env["RUBYOPT"] = ["-I#{File.expand_path("..", __dir__)}", ENV["RUBYOPT"]].compact.join(" ") - - command_name = Gem.win_platform? ? [Gem.ruby, "bin/rspec"] : "bin/rspec" - - command = [ - *command_name, - *extra_args, - "--seed", rand(0xFFFF).to_s, - "--format", "ParallelTests::RSpec::RuntimeLogger", - "--out", @runtime_log, - "--require", File.expand_path("windows_json_rows_formatter", __dir__), - "--format", "TurboTests::WindowsJsonRowsFormatter", - *tests - ] - - if @verbose - command_str = [ - env.map {|k, v| "#{k}=#{v}" }.join(" "), - command.join(" "), - ].select {|x| x.size > 0 }.join(" ") - - warn "Process #{process_id}: #{command_str}" - end - - stdin, stdout, stderr, wait_thr = Open3.popen3(env, *command) - stdin.close - - @threads << - Thread.new do - require "json" - 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 = JSON.parse(message, symbolize_names: true) - message[:process_id] = process_id - @messages << message - end - - @messages << { type: "exit", process_id: process_id } - end - - @threads << start_copy_thread(stderr, STDERR) - - @threads << Thread.new do - unless wait_thr.value.success? - @messages << { type: "error" } - end - end - - wait_thr - end - end - end -end diff --git a/turbo_tests.gemspec b/turbo_tests.gemspec index 52064e1..f769992 100644 --- a/turbo_tests.gemspec +++ b/turbo_tests.gemspec @@ -21,6 +21,8 @@ Gem::Specification.new do |spec| spec.add_dependency "rspec", ">= 3.10" spec.add_dependency "parallel_tests", ">= 3.3.0", "< 5" + spec.add_dependency "fileutils", "~> 1.4" + spec.add_dependency "open3", "~> 0.1" spec.add_development_dependency "pry", "~> 0.14" From 1fa426c73e1aa6cad80efee3147d0370b8287e4e Mon Sep 17 00:00:00 2001 From: ilyazub Date: Wed, 10 Apr 2024 15:33:22 +0200 Subject: [PATCH 5/5] Bump version to 2.2.2 --- Gemfile.lock | 2 +- lib/turbo_tests/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d11f2a1..9c481fe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - turbo_tests (2.2.1) + turbo_tests (2.2.2) fileutils (~> 1.4) json (~> 2.3) open3 (~> 0.1) 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