<commit_before>plugin_root = File.join(File.dirname(__FILE__), '..')
require File.join(plugin_root, 'lib', 'parallel_specs')

namespace :spec do
  namespace :parallel do
    desc "prepare parallel test running by calling db:reset for every test database needed with spec:parallel:"
    task :prepare, :count do |t,args|
      num_processes = args[:count] ? args[:count] : 2
      num_processes.times do |i|
        puts "Preparing test database #{i+1}"
        `export INSTANCE=#{i==0?'':i+1}; export RAILS_ENV=test; rake db:reset`
      end
    end
  end

  desc "run specs in parallel with spec:parallel[count]"
  task :parallel, :count do |t,args|
    num_processes = args[:count] ? args[:count] : 2
    
    puts "running specs in #{num_processes} processes"
    start = Time.now

    groups = ParallelSpecs.specs_in_groups(RAILS_ROOT, num_processes)
    puts "#{groups.sum{|g|g.size}} specs in #{groups[0].size} specs per process"

    #run each of the groups
    pids = []
    num_processes.times do |i|
      puts "starting process #{i+1}"
      pids << Process.fork do
        sh "export INSTANCE=#{i==0?'':i+1}; script/spec -O spec/spec.opts #{groups[i]*' '}"
      end
    end

    #handle user interrup<commit_msg>Made the runner a bit less chatty (the commands can get quite long when you have hundreds of specs).<commit_after>plugin_root = File.join(File.dirname(__FILE__), '..')
require File.join(plugin_root, 'lib', 'parallel_specs')

namespace :spec do
  namespace :parallel do
    desc "prepare parallel test running by calling db:reset for every test database needed with spec:parallel:"
    task :prepare, :count do |t,args|
      num_processes = args[:count] ? args[:count] : 2
      num_processes.times do |i|
        puts "Preparing test database #{i+1}"
        `export INSTANCE=#{i==0?'':i+1}; export RAILS_ENV=test; rake db:reset`
      end
    end
  end

  desc "run specs in parallel with spec:parallel[count]"
  task :parallel, :count do |t,args|
    num_processes = args[:count] ? args[:count] : 2
    
    puts "Running specs in #{num_processes} processes"
    start = Time.now

    groups = ParallelSpecs.specs_in_groups(RAILS_ROOT, num_processes)
    puts "#{groups.sum{|g|g.size}} specs in #{groups[0].size} specs per process"

    #run each of the groups
    pids = []
    num_processes.times do |i|
      pids << Process.fork do
        system "export INSTANCE=#{i==0?'':i+1}; script/spec -O spec/spec.opts #{groups[i]*' '}"
      end
    end

    #handle user interrup
{'fraction_non_alphanumeric': 0.1297923322683706, 'fraction_numerical': 0.006789137380191693, 'mean_word_length': 3.4572953736654806, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6581061', 'n_tokens_mistral': 844, 'n_tokens_neox': 819, 'n_words': 245}