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

Windows support #50

Merged
merged 7 commits into from
Apr 16, 2024
Merged
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
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: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
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
Loading