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 3 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: 2 additions & 0 deletions lib/turbo_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ def notification
end
end
end

require "turbo_tests/windows" if RUBY_PLATFORM.match?(/mingw|mswin/)
75 changes: 75 additions & 0 deletions lib/turbo_tests/windows.rb
Original file line number Diff line number Diff line change
@@ -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
deivid-rodriguez marked this conversation as resolved.
Show resolved Hide resolved
env["RUBYOPT"] = ["-I#{File.expand_path("..", __dir__)}", ENV["RUBYOPT"]].compact.join(" ")

command_name = Gem.win_platform? ? [Gem.ruby, "bin/rspec"] : "bin/rspec"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the best way to detect Bundler binstubs and/or if bundle exec is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point too! Using bin/rspec directly is quite specific to our environment. I guess we could detect whether there's a bin/rspec file relative to the cwd, and otherwise use bundle exec rspec?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could detect whether there's a bin/rspec file relative to the cwd, and otherwise use bundle exec rspec

Will Windows correctly handle this if we append $PWD/bin to ENV["PATH"] instead of detecting bin/rspec? (I'm new to Bundler internals. Below is a hacky pseudo-code.)

env["PATH"] << ":#{File.expand_path("bin", __dir__)}"

command_name = ENV["BUNDLE_BIN_PATH"] ? [ENV["BUNDLE_BIN_PATH"], "exec", "rspec"] : "rspec"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would handle it fine, but I'm not sure it's a good idea since it would have global side effects. Users have other scripts in bin/ and maybe won't expect turbo_tests to automatically set things up so that those other scripts start getting selected when their tests run processes? Not sure.

Maybe we can start leaving things as they are regarding building the command name for now. I could configure $LOAD_PATH on our side before launching turbo_tests so that our binstub gets properly loaded.


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",
deivid-rodriguez marked this conversation as resolved.
Show resolved Hide resolved
*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
Loading