Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit

Permalink
Merge pull request #66 from zopaUK/ability-to-execute-nunit-in-parallel
Browse files Browse the repository at this point in the history
Nunit test projects can run in parallel
  • Loading branch information
lukesmith committed Apr 7, 2016
2 parents 3c2b0be + 1cf18f3 commit 8f8d467
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions lib/bozo/test_runners/nunit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ module Bozo::TestRunners
# runner_path # should return the path to the runners executable
# runner_args # should return the arguments to be passed to use
class Nunit

def initialize
@projects = []
@include = []
@exclude = []
@execute_in_parallel = false
end

def destination(destination)
Expand Down Expand Up @@ -47,6 +48,10 @@ def exclude(exclude)
cannot_define_both_include_and_exclude_categories if @include.any?
@exclude << exclude
end

def execute_in_parallel
@execute_in_parallel = true
end

def to_s
"Run tests with nunit against projects #{@projects}"
Expand Down Expand Up @@ -77,18 +82,21 @@ def runner_path
# Returns the arguments required for the runner's executable.
#
# @returns [Array]
def runner_args
def runner_args(projects = nil, report_prefix = nil)
projects = @projects if projects.nil?
report_prefix = Time.now.to_i if report_prefix.nil?

args = []

@projects.each do |project|
projects.each do |project|
expand_and_glob('temp', 'msbuild', project, '**', "#{project}.dll").each do |test_dll|
args << "\"#{test_dll}\""
end
end
args << '/nologo'

report_path = @report_path
report_path = expand_path('temp', 'nunit', "#{Time.now.to_i}-nunit-report.xml") unless report_path
report_path = expand_path('temp', 'nunit', "#{report_prefix}-nunit-report.xml") unless report_path

# Ensure the directory is there because NUnit won't make it
FileUtils.mkdir_p File.dirname(report_path)
Expand All @@ -101,7 +109,29 @@ def runner_args
end

def execute
execute_command :nunit, [runner_path] << runner_args
if @execute_in_parallel
failed_projects = []
threads = []

@projects.each do |project|
t = Thread.new {
begin
execute_command :nunit, [runner_path] << runner_args([project], "#{project}-#{Time.now.to_i}")
rescue
failed_projects << project
end
}
threads.push(t)
end

threads.each(&:join)

if failed_projects.length > 0
raise Bozo::ExecutionError.new(:nunit, [runner_path] << failed_projects, 1)
end
else
execute_command :nunit, [runner_path] << runner_args
end
end

private
Expand Down

0 comments on commit 8f8d467

Please sign in to comment.