Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/grosser/parallel_specs
Browse files Browse the repository at this point in the history
Conflicts:
	README.markdown
	lib/parallel_specs.rb
	tasks/parallel_specs.rake
  • Loading branch information
joakimk committed Jun 7, 2009
2 parents 36ea30f + 64fbc99 commit 5d9bfaa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
7 changes: 3 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Run like hell :D

Example output
--------------
2 processes: 209 specs
2 processes for 210 specs, ~ 105 specs per process
... test output ...
Took 47.319378 seconds
Took 29.925333 seconds

TIPS
====
Expand All @@ -41,8 +41,7 @@ TIPS
TODO
====
- find out how many CPUs the user has [here](http://stackoverflow.com/questions/891537/ruby-detect-number-of-cpus-installed)
- sync the output, so that results do not appear all at once
- grab the 'xxx examples ..' line and display them at the bottom
- grab the 'xxx examples ..' line and display them after all tests have finished

Authors
====
Expand Down
8 changes: 8 additions & 0 deletions lib/parallel_specs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ def specs_in_groups(root, num)

groups
end

def run_tests(test_files, process_number)
cmd = "export RAILS_ENV=test ; export TEST_ENV_NUMBER=#{process_number==0?'':process_number+1} ; export RSPEC_COLOR=1 ; script/spec -O spec/spec.opts #{test_files*' '}"
f = open("|#{cmd}")
while out = f.gets(".")
print out
end
end

private

Expand Down
26 changes: 12 additions & 14 deletions tasks/parallel_specs.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,32 @@ namespace :spec do

desc "run specs in parallel with spec:parallel[count]"
task :parallel, :count do |t,args|
start = Time.now
require File.join(File.dirname(__FILE__), '..', 'lib', 'parallel_specs')

plugin_root = File.join(File.dirname(__FILE__), '..')
require File.join(plugin_root, 'lib', 'parallel_specs')
start = Time.now

num_processes = (args[:count] || 2).to_i
groups = ParallelSpecs.specs_in_groups(RAILS_ROOT, num_processes)
puts "#{num_processes} processes: #{groups.sum{|g|g.size}} specs"

#run each of the groups
puts "Be patient, output comes when spec are finished..."
num_specs = groups.sum { |g| g.size }
puts "#{num_processes} processes for #{num_specs} specs, ~ #{num_specs / num_processes} specs per process"

#run each of the groups
pids = []
num_processes.times do |i|
groups.each_with_index do |files, process_number|
pids << Process.fork do
puts `export RAILS_ENV=test ; export TEST_ENV_NUMBER=#{i==0?'':i+1} ; script/spec -O spec/spec.opts #{groups[i]*' '}`
ParallelSpecs.run_tests(files, process_number)
end
end

#handle user interrup
interrupt_handler = lambda do
STDERR.puts "interrupt, exiting ..."
pids.each { |pid| Process.kill "KILL", pid }
#handle user interrup (Ctrl+c)
Signal.trap'SIGINT' do
STDERR.puts "Parallel specs interrupted, exiting ..."
pids.each {|pid| Process.kill "KILL", pid}
exit 1
end
Signal.trap 'SIGINT', interrupt_handler

#wait for everybody to finish
#wait for processes to finish
pids.each{ Process.wait }

#report total time taken
Expand Down

0 comments on commit 5d9bfaa

Please sign in to comment.