From 1ee84e16e5e56afff1719b65d571bb4290f647ed Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 9 Dec 2018 22:58:49 +0000 Subject: [PATCH] Change fork isolation to be more nitpicky about exceptions to rescue --- lib/mutant/isolation/fork.rb | 4 +-- spec/unit/mutant/isolation/fork_spec.rb | 44 ++++++++++++++----------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/lib/mutant/isolation/fork.rb b/lib/mutant/isolation/fork.rb index bde30ba6..1df59499 100644 --- a/lib/mutant/isolation/fork.rb +++ b/lib/mutant/isolation/fork.rb @@ -36,8 +36,6 @@ module Mutant pid = start_child or return ForkError.new read_child_result(pid) - rescue => exception - Result::Exception.new(exception) end private @@ -58,6 +56,8 @@ module Mutant writer.close Result::Success.new(marshal.load(reader)) + rescue ArgumentError, EOFError => exception + Result::Exception.new(exception) ensure process.waitpid(pid) end diff --git a/spec/unit/mutant/isolation/fork_spec.rb b/spec/unit/mutant/isolation/fork_spec.rb index 5d1f9dc6..19987ca8 100644 --- a/spec/unit/mutant/isolation/fork_spec.rb +++ b/spec/unit/mutant/isolation/fork_spec.rb @@ -147,28 +147,32 @@ RSpec.describe Mutant::Isolation::Fork do end end - context 'when unexpected exception was raised' do - let(:exception) { RuntimeError.new } + context 'when expected exception was raised when reading from child' do + [ArgumentError, EOFError].each do |exception_class| + context "on #{exception_class}" do + let(:exception) { exception_class.new } - let(:expectations) do - [ - *prefork_expectations, - fork_success, - *killfork, - { - receiver: writer, - selector: :close, - reaction: { - exception: exception - } - }, - waitpid - ].map(&XSpec::MessageExpectation.method(:parse)) - end + let(:expectations) do + [ + *prefork_expectations, + fork_success, + *killfork, + { + receiver: writer, + selector: :close, + reaction: { + exception: exception + } + }, + waitpid + ].map(&XSpec::MessageExpectation.method(:parse)) + end - specify do - XSpec::ExpectationVerifier.verify(self, expectations) do - expect(subject).to eql(Mutant::Isolation::Result::Exception.new(exception)) + specify do + XSpec::ExpectationVerifier.verify(self, expectations) do + expect(subject).to eql(Mutant::Isolation::Result::Exception.new(exception)) + end + end end end end