Skip to content

Commit

Permalink
Updates Rake spec:unit task(s) in preparation for 1.9/2.1 switch.
Browse files Browse the repository at this point in the history
- Rename Rake task 'spec:unit:ruby_gems' as 'spec:unit:ruby'.
- Generate unit rake tasks for each subproject.

[#101914406](https://www.pivotaltracker.com/story/show/101914406)
  • Loading branch information
Corey Innis authored and tylerschultz committed Oct 2, 2015
1 parent 072288f commit 0c7e065
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,4 +1,4 @@
script: 'bundle exec rake --trace spec:unit:ruby_gems ci:publish_coverage_report'
script: 'bundle exec rake --trace spec:unit:ruby ci:publish_coverage_report'

before_install:
- 'sudo apt-get update'
Expand Down
71 changes: 48 additions & 23 deletions bosh-dev/lib/bosh/dev/tasks/spec.rake
Expand Up @@ -69,52 +69,77 @@ namespace :spec do

task :integration => %w(spec:integration:agent)

namespace :unit do
desc 'Run unit tests for each BOSH component gem in parallel'
task ruby_gems: %w(rubocop) do
trap('INT') { exit }
def unit_exec(build, log_file = nil)
command = unit_cmd(build, log_file)

# inject command name so coverage results for each component don't clobber others
if system({'BOSH_BUILD_NAME' => build}, "cd #{build} && #{command}")
puts "----- BEGIN #{build}"
puts " #{command}"
print File.read(log_file)
puts "----- END #{build}\n\n"
else
raise("#{build} failed to build unit tests: #{File.read(log_file)}")
end
end

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

def unit_files(build)
cpi_builds.include?(build) ? 'spec/unit/' : 'spec/'
end

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

cpi_builds = builds.select { |f| File.directory?(f) && f.end_with?("_cpi") }

spec_logs = Dir.mktmpdir
def cpi_builds
@cpi_builds ||= unit_builds.select { |f| File.directory?(f) && f.end_with?("_cpi") }
end

puts "Logging spec results in #{spec_logs}"
namespace :unit do
desc 'Run unit tests for each BOSH component gem in parallel'
task ruby: %w(rubocop) do
trap('INT') { exit }
log_dir = Dir.mktmpdir
puts "Logging spec results in #{log_dir}"

max_threads = ENV.fetch('BOSH_MAX_THREADS', 10).to_i
null_logger = Logging::Logger.new('Ignored')
Bosh::ThreadPool.new(max_threads: max_threads, logger: null_logger).wrap do |pool|
builds.each do |build|
unit_builds.each do |build|
pool.process do
log_file = "#{spec_logs}/#{build}.log"
rspec_files = cpi_builds.include?(build) ? "spec/unit/" : "spec/"
rspec_cmd = "rspec --tty --backtrace -c -f p #{rspec_files}"

# inject command name so coverage results for each component don't clobber others
if system({'BOSH_BUILD_NAME' => build}, "cd #{build} && #{rspec_cmd} > #{log_file} 2>&1")
puts "----- BEGIN #{build}"
puts " #{rspec_cmd}"
print File.read(log_file)
puts "----- END #{build}\n\n"
else
raise("#{build} failed to build unit tests: #{File.read(log_file)}")
end
unit_exec(build, "#{log_dir}/#{build}.log")
end
end

pool.wait
end
end

(unit_builds - cpi_builds).each do |build|
desc 'Run unit tests for each BOSH component gem in parallel'
task build.sub(/^bosh[_-]/, '').intern do
trap('INT') { exit }
unit_exec(build)
end
end

task(:agent) do
# Do not use exec because this task is part of other tasks
sh('cd go/src/github.com/cloudfoundry/bosh-agent/ && bin/test-unit')
end
end

task :unit => %w(spec:unit:ruby_gems spec:unit:agent)
task :unit => %w(spec:unit:ruby spec:unit:agent)

namespace :external do
desc 'AWS bootstrap CLI can provision and destroy resources'
Expand Down

0 comments on commit 0c7e065

Please sign in to comment.