From 7040a30b35cf02d570011a106b9d5a3d08d96540 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 2 Jun 2014 15:10:32 +0000 Subject: [PATCH] Speedup corpus integration test via the parallel gem --- mutant.gemspec | 1 + spec/integration/mutant/corpus_spec.rb | 54 ++++++++++++++------------ 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/mutant.gemspec b/mutant.gemspec index bbfef4e3..32ff8695 100644 --- a/mutant.gemspec +++ b/mutant.gemspec @@ -39,4 +39,5 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency('concord', '~> 0.1.5') gem.add_development_dependency('bundler', '~> 1.3', '>= 1.3.5') + gem.add_development_dependency('parallel', '~> 1.0.0') end diff --git a/spec/integration/mutant/corpus_spec.rb b/spec/integration/mutant/corpus_spec.rb index 656630cf..e701638e 100644 --- a/spec/integration/mutant/corpus_spec.rb +++ b/spec/integration/mutant/corpus_spec.rb @@ -1,5 +1,6 @@ # encoding: UTF-8 +require 'parallel' require 'spec_helper' describe 'Mutant on ruby corpus' do @@ -12,6 +13,8 @@ describe 'Mutant on ruby corpus' do pending 'Corpus test is deactivated on 1.9.3' if RUBY_VERSION.eql?('1.9.3') end + MUTEX = Mutex.new + class Project include Anima.new(:name, :repo_uri, :exclude) @@ -26,41 +29,28 @@ describe 'Mutant on ruby corpus' do # rubocop:disable MethodLength def verify checkout - total = 0 - parse_errors = [] start = Time.now - Pathname.glob(repo_path.join('**/*.rb')).sort.each do |path| - puts "Generating mutations for: #{path}" - begin - node = Parser::CurrentRuby.parse(path.read) - # Ignore known parser bugs - rescue ArgumentError, EncodingError - parse_errors << path - next - end - next if node.nil? + total = Parallel.map(Pathname.glob(repo_path.join('**/*.rb')).sort_by(&:size).reverse, finish: method(:progress)) do |path| count = 0 - Mutant::Mutator::Node.each(node) do - count += 1 - if (count % 1000).zero? - puts count + node = + begin + Parser::CurrentRuby.parse(path.read) + rescue EncodingError, ArgumentError + end + unless node.nil? + Mutant::Mutator::Node.each(node) do + count += 1 end end - puts "Mutations: #{count}" - total += count - end + count + end.inject(0, :+) took = Time.now - start puts format( - 'Total Mutations/Time/Parse-Errors: %s/%0.2fs/%i - %0.2f/s', + 'Total Mutations/Time/Parse-Errors: %s/%0.2fs - %0.2f/s', total, took, - parse_errors.size, total / took ) - if parse_errors.any? - puts 'Files with parse errors:' - parse_errors.each(&method(:puts)) - end self end @@ -95,6 +85,20 @@ describe 'Mutant on ruby corpus' do TMP.join(name) end + # Print progress + # + # @param [Pathname] path + # @param [Fixnum] _index + # @param [Fixnum] count + # + # @return [undefined] + # + def progress(path, _index, count) + MUTEX.synchronize do + puts 'Mutations - %4i - %s' % [count, path] + end + end + # Helper method to execute system commands # # @param [Array] arguments