2014-10-23 07:37:53 -04:00
|
|
|
module Mutant
|
|
|
|
class Runner
|
|
|
|
# Mutation killing worker receiving work from parent
|
|
|
|
class Worker
|
|
|
|
include Adamantium::Flat, Anima.new(:config, :id, :parent)
|
|
|
|
|
|
|
|
private_class_method :new
|
|
|
|
|
|
|
|
# Run worker
|
|
|
|
#
|
|
|
|
# @param [Hash<Symbol, Object] attributes
|
|
|
|
#
|
|
|
|
# @return [Actor::Sender]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.run(attributes)
|
|
|
|
attributes.fetch(:config).actor_env.spawn do |actor|
|
|
|
|
worker = new(attributes)
|
2014-12-07 16:14:54 -05:00
|
|
|
worker.__send__(:run, actor)
|
2014-10-23 07:37:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Worker loop
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
# rubocop:disable Lint/Loop
|
|
|
|
#
|
|
|
|
def run(actor)
|
|
|
|
begin
|
|
|
|
parent.call(Actor::Message.new(:ready, actor.sender))
|
|
|
|
end until handle(actor.receiver.call)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Handle job
|
|
|
|
#
|
|
|
|
# @param [Message] message
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
#
|
2014-12-01 13:33:47 -05:00
|
|
|
# @api private
|
|
|
|
#
|
2014-10-23 07:37:53 -04:00
|
|
|
def handle(message)
|
|
|
|
type, payload = message.type, message.payload
|
|
|
|
case message.type
|
|
|
|
when :job
|
|
|
|
handle_job(payload)
|
|
|
|
nil
|
|
|
|
when :stop
|
|
|
|
true
|
|
|
|
else
|
|
|
|
fail Actor::ProtocolError, "Unknown command: #{type.inspect}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Handle mutation
|
|
|
|
#
|
|
|
|
# @param [Job] job
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def handle_job(job)
|
2014-12-07 16:53:36 -05:00
|
|
|
parent.call(Actor::Message.new(:result, JobResult.new(job: job, result: run_mutation(job.mutation))))
|
2014-10-23 07:37:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Run mutation
|
|
|
|
#
|
|
|
|
# @param [Mutation] mutation
|
|
|
|
#
|
2014-12-07 17:02:24 -05:00
|
|
|
# @return [Result::Mutation]
|
2014-10-23 07:37:53 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-12-07 16:53:36 -05:00
|
|
|
def run_mutation(mutation)
|
2014-11-27 11:34:08 -05:00
|
|
|
test_result = mutation.kill(config.isolation, config.integration)
|
|
|
|
Result::Mutation.new(
|
|
|
|
mutation: mutation,
|
|
|
|
test_result: test_result
|
2014-10-23 07:37:53 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
end # Worker
|
|
|
|
end # Runner
|
|
|
|
end # Mutant
|