2014-06-08 13:55:13 -04:00
|
|
|
module Mutant
|
2014-08-07 12:00:31 -04:00
|
|
|
# Module providing isolation
|
2014-06-08 13:55:13 -04:00
|
|
|
module Isolation
|
|
|
|
Error = Class.new(RuntimeError)
|
|
|
|
|
2014-07-05 22:11:31 -04:00
|
|
|
module None
|
|
|
|
|
|
|
|
# Call block in isolation
|
|
|
|
#
|
|
|
|
# @return [Object]
|
|
|
|
#
|
|
|
|
# @raise [Error]
|
|
|
|
# if block terminates abnormal
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.call(&block)
|
2014-06-24 20:13:24 -04:00
|
|
|
block.call
|
2014-07-05 22:11:31 -04:00
|
|
|
rescue => exception
|
|
|
|
fail Error, exception
|
|
|
|
end
|
2014-06-08 13:55:13 -04:00
|
|
|
end
|
|
|
|
|
2014-07-05 22:11:31 -04:00
|
|
|
module Fork
|
|
|
|
|
|
|
|
# Call block in isolation
|
|
|
|
#
|
|
|
|
# This isolation implements the fork strategy.
|
|
|
|
# Future strategies will probably use a process pool that can
|
|
|
|
# handle multiple mutation kills, in-isolation at once.
|
|
|
|
#
|
|
|
|
# @return [Object]
|
|
|
|
# returns block execution result
|
|
|
|
#
|
|
|
|
# @raise [Error]
|
|
|
|
# if block terminates abnormal
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.call(&block)
|
2014-08-11 11:11:22 -04:00
|
|
|
Parallel.map([block], in_processes: 1, &block.method(:call)).first
|
2014-07-05 22:11:31 -04:00
|
|
|
rescue Parallel::DeadWorker => exception
|
|
|
|
fail Error, exception
|
|
|
|
end
|
|
|
|
|
|
|
|
end # Fork
|
|
|
|
|
2014-06-08 13:55:13 -04:00
|
|
|
end # Isolator
|
|
|
|
end # Mutant
|