diff --git a/Gemfile b/Gemfile index 11d8d794..7da3cf77 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,8 @@ end group :test do gem 'mocha' - gem 'minitest', :require => 'minitest/autorun' + gem 'parallel' + gem 'minitest', :require => false end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index beab93d0..9d102f5d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,6 +107,7 @@ GEM systemu (~> 2.2.0) yajl-ruby ori (0.1.0) + parallel (0.5.14) polyglot (0.3.3) rake (0.9.2) rbx-require-relative (0.0.5) @@ -153,6 +154,7 @@ DEPENDENCIES knife-solo! minitest mocha + parallel rake ruby-debug ruby-debug19 diff --git a/test/integration_helper.rb b/test/integration_helper.rb index f29b3e02..08248a23 100644 --- a/test/integration_helper.rb +++ b/test/integration_helper.rb @@ -1,9 +1,8 @@ -require 'rubygems' -require 'bundler/setup' -Bundler.require(:default, :test) -require 'pathname' +require 'test_helper' -class IntegrationTest < MiniTest::Unit::TestCase +MiniTest::Parallel.processor_count = [Dir['test/integration/*_test.rb'].size, 5].min + +class IntegrationTest < TestCase def self.servers @servers ||= [] end diff --git a/test/minitest/parallel.rb b/test/minitest/parallel.rb new file mode 100644 index 00000000..6d132de4 --- /dev/null +++ b/test/minitest/parallel.rb @@ -0,0 +1,41 @@ +# https://github.com/ngauthier/minitest-parallel +if defined?(MiniTest) + raise "Do not require minitest before minitest/parallel\n" +end +require 'parallel' +require 'minitest/unit' + +module MiniTest::Parallel + def self.included(base) + base.class_eval do + alias_method :_run_suites_in_series, :_run_suites + alias_method :_run_suites, :_run_suites_in_parallel + end + end + + def self.processor_count=(procs) + @processor_count = procs + end + + def self.processor_count + @processor_count ||= Parallel.processor_count + end + + def _run_suites_in_parallel(suites, type) + result = Parallel.map(suites, :in_processes => MiniTest::Parallel.processor_count) do |suite| + ret = _run_suite(suite, type) + { + :failures => failures, + :errors => errors, + :report => report, + :run_suite_return => ret + } + end + self.failures = result.inject(0) {|sum, x| sum + x[:failures] } + self.errors = result.inject(0) {|sum, x| sum + x[:errors] } + self.report = result.inject([]) {|sum, x| sum + x[:report] } + result.map {|x| x[:run_suite_return] } + end +end + +MiniTest::Unit.send(:include, MiniTest::Parallel) diff --git a/test/test_helper.rb b/test/test_helper.rb index 313080a2..fe52fe89 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,11 +1,13 @@ require 'rubygems' -require 'test/unit' require 'bundler' Bundler.require Bundler.require(:test) -class TestCase < Test::Unit::TestCase +require 'minitest/parallel' +require 'minitest/autorun' + +class TestCase < MiniTest::Unit::TestCase def default_test super unless self.class == TestCase end