Change fork isolation to be more nitpicky about exceptions to rescue
This commit is contained in:
parent
47bb9c1839
commit
1ee84e16e5
2 changed files with 26 additions and 22 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue