Skip to content

Commit

Permalink
Change to native parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Mar 8, 2024
1 parent d38756c commit e1bd86a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ PLATFORMS
DEPENDENCIES
mutant!
mutant-license!
parallel (~> 1.3)
rspec (~> 3.10)
rspec-core (~> 3.10)
rspec-its (~> 1.3.0)
Expand Down
1 change: 0 additions & 1 deletion mutant.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency('sorbet-runtime', '~> 0.5.0')
gem.add_runtime_dependency('unparser', '~> 0.6.9')

gem.add_development_dependency('parallel', '~> 1.3')
gem.add_development_dependency('rspec', '~> 3.10')
gem.add_development_dependency('rspec-core', '~> 3.10')
gem.add_development_dependency('rspec-its', '~> 1.3.0')
Expand Down
58 changes: 52 additions & 6 deletions spec/support/corpus.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'etc'
require 'mutant'
require 'parallel'

Expand All @@ -25,8 +26,6 @@ class Project
FINISH_MESSAGE = 'Mutations - %4i - %s'
RUBY_GLOB_PATTERN = '**/*.rb'

DEFAULT_MUTATION_COUNT = 0

include Adamantium, Anima.new(
:mutation_coverage,
:mutation_generation,
Expand Down Expand Up @@ -73,6 +72,32 @@ def concurrency_limits
end
end

class Sink
include Mutant::Parallel::Sink

attr_reader :total

def initialize
@total = 0
end

def stop?
false
end

def status
@total
end

def response(response)
if response.error
Mutant::WORLD.stderr.puts(response.log)
fail response.error
end
@total += response.result
end
end

# Verify mutation generation
#
# @return [self]
Expand All @@ -92,11 +117,32 @@ def verify_mutation_generation
in_processes: Etc.nprocessors
}

total = Parallel.map(effective_ruby_paths, options, &method(:check_generation))
.reduce(DEFAULT_MUTATION_COUNT, :+)
sink = Sink.new

parallel_config = Mutant::Parallel::Config.new(
block: method(:check_generation),
jobs: Etc.nprocessors,
sink: sink,
timeout: nil,
process_name: 'mutation-generation',
source: Mutant::Parallel::Source::Array.new(jobs: effective_ruby_paths),
on_process_start: ->(_) {},
thread_name: 'mutation-generation'
)

elapsed = Mutant::WORLD.timer.elapsed do
driver = Mutant::Parallel.async(
config: parallel_config,
world: Mutant::WORLD
)

loop do
status = driver.wait_timeout(1)
break if status.done?
end
end

took = timer.now - start
puts MUTATION_GENERATION_MESSAGE % [total, took, total / took]
puts MUTATION_GENERATION_MESSAGE % [sink.total, elapsed, sink.total / elapsed]
self
end

Expand Down

0 comments on commit e1bd86a

Please sign in to comment.