Skip to content

Commit

Permalink
Set up parallel minitests
Browse files Browse the repository at this point in the history
  • Loading branch information
matschaffer committed Feb 7, 2012
1 parent 1ac5cce commit 66ec3d4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -153,6 +154,7 @@ DEPENDENCIES
knife-solo!
minitest
mocha
parallel
rake
ruby-debug
ruby-debug19
Expand Down
9 changes: 4 additions & 5 deletions test/integration_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
41 changes: 41 additions & 0 deletions test/minitest/parallel.rb
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 4 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 66ec3d4

Please sign in to comment.