#!/usr/bin/env ruby require 'rubygems' require 'optparse' require 'parallel' $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') require "parallel_tests" options = {} OptionParser.new do |opts| opts.banner = < 0 num_processes = options[:count] || Parallel.processor_count num_processes = num_processes * (options[:multiply] || 1) if options[:execute] Parallel.in_processes(num_processes) do |i| ParallelTests.execute_command(options[:execute], i) end else lib, name, task = { 'test' => ["tests", "test", "test"], 'spec' => ["specs", "spec", "spec"], 'features' => ["cucumber", "feature", "features"] }[options[:type]||'test'] require "parallel_#{lib}" klass = eval("Parallel#{lib.capitalize}") start = Time.now tests_folder = File.join(task, options[:path_prefix].to_s) tests_folder = File.join(options[:root], tests_folder) unless options[:root].to_s.empty? groups = klass.tests_in_groups(options[:files] || tests_folder, num_processes, :no_sort => options[:no_sort]) num_processes = groups.size #adjust processes to groups abort "no #{name}s found!" if groups.size == 0 num_tests = groups.inject(0){|sum,item| sum + item.size } puts "#{num_processes} processes for #{num_tests} #{name}s, ~ #{num_tests / groups.size} #{name}s per process" output = Parallel.map(groups, :in_processes => num_processes) do |group| klass.run_tests(group, groups.index(group), options[:test_options]) end #parse and print results results = klass.find_results(output*"") puts "" puts "Results:" results.each{|r| puts r} #report total time taken puts "" puts "Took #{Time.now - start} seconds" #exit with correct status code # - rake parallel:test && echo 123 ==> 123 should not show up when test failed # - rake parallel:test db:reset ==> works when tests succeed abort "#{name.capitalize}s Failed" if klass.failed?(results) end