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

🐞 Use Rake's sh method to execute TestRunner's command #2560

Merged
merged 2 commits into from
Sep 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
8 changes: 6 additions & 2 deletions src/bosh-dev/lib/bosh/dev/tasks/spec.rake
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,18 @@ namespace :spec do
desc "Run unit tests for the #{build} component"
task build.sub(/^bosh[_-]/, '').intern do
trap('INT') { exit }
runner.unit_exec(build)
Dir.chdir build do
sh("#{runner.unit_cmd(build)}")
end
end

namespace build.sub(/^bosh[_-]/, '').intern do
desc "Run parallel unit tests for the #{build} component"
task :parallel do
trap('INT') { exit }
runner.unit_exec(build, parallel: true)
Dir.chdir build do
sh("#{runner.unit_parallel(build)}")
end
end
end
end
Expand Down
46 changes: 24 additions & 22 deletions src/bosh-dev/lib/bosh/dev/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ def ruby(parallel: false)
end
end

def unit_cmd(log_file = nil)
"".tap do |cmd|
cmd << 'rspec --tty --backtrace -c -f p spec'
cmd << " > #{log_file} 2>&1" if log_file
end
end

def unit_parallel(build_name, log_file = nil)
cmd = "parallel_test --test-options '--no-fail-fast' --type rspec --runtime-log /tmp/bosh_#{build_name}_parallel_runtime_rspec.log spec"
cmd << " > #{log_file} 2>&1" if log_file
cmd
end

def unit_builds
@unit_builds ||= begin
builds = Dir['*'].select do |f|
File.directory?(f) && File.exist?("#{f}/spec")
end.sort
builds -= %w(bat)
end
end

private

def unit_exec(build, log_file: nil, parallel: false)
lines = []
command = parallel ? unit_parallel(build, log_file) : unit_cmd(log_file)
Expand All @@ -54,27 +78,5 @@ def unit_exec(build, log_file: nil, parallel: false)
{:lines => lines, :error => true}
end
end

def unit_cmd(log_file = nil)
"".tap do |cmd|
cmd << 'rspec --tty --backtrace -c -f p spec'
cmd << " > #{log_file} 2>&1" if log_file
end
end

def unit_parallel(build_name, log_file = nil)
cmd = "parallel_test --test-options '--no-fail-fast' --type rspec --runtime-log /tmp/bosh_#{build_name}_parallel_runtime_rspec.log spec"
cmd << " > #{log_file} 2>&1" if log_file
cmd
end

def unit_builds
@unit_builds ||= begin
builds = Dir['*'].select do |f|
File.directory?(f) && File.exist?("#{f}/spec")
end.sort
builds -= %w(bat)
end
end
end
end
4 changes: 2 additions & 2 deletions src/bosh-dev/spec/unit/bosh/dev/test_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ module Bosh::Dev

it 'changes directory to the build and shells out to #unit_cmd' do
expect(Kernel).to receive(:system).with({ 'BOSH_BUILD_NAME' => build }, "cd #{build} && #{runner.unit_cmd}")
runner.unit_exec(build)
runner.send(:unit_exec, build)
end

it 'signals failure if the command fails' do
allow(Kernel).to receive(:system).and_return(false)

retval = runner.unit_exec(build)
retval = runner.send(:unit_exec, build)
expect(retval[:error]).to equal(true)
end
end
Expand Down
Loading