Skip to content

Commit

Permalink
Merge branch 'master' of github.com:serpapi/turbo_tests into remove-j…
Browse files Browse the repository at this point in the history
…son-gem-explicit-dependency
  • Loading branch information
ilyazub committed Apr 16, 2024
2 parents ced6eb7 + 876a33d commit 4f1cc37
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/turbo_tests.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require "securerandom"
require "open3"
require "fileutils"
require "json"

require "rspec"

require "parallel_tests"
Expand Down
2 changes: 1 addition & 1 deletion lib/turbo_tests/json_rows_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 31 additions & 27 deletions lib/turbo_tests/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
[
Expand All @@ -158,50 +158,54 @@ 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)
stdin.close

@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
Expand Down
2 changes: 1 addition & 1 deletion lib/turbo_tests/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TurboTests
VERSION = "2.2.1"
VERSION = "2.2.2"
end

0 comments on commit 4f1cc37

Please sign in to comment.