Class: Mutant::Isolation::Fork Private
- Inherits:
-
Mutant::Isolation
- Object
- Mutant::Isolation
- Mutant::Isolation::Fork
- Defined in:
- lib/mutant/isolation/fork.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Isolation via the fork(2) systemcall.
We do inject so many globals and common patterns to make this unit specifiable without mocking the globals and more important: Not having mutations that bypass mocks into a real world side effect.
Constant Summary
Constants inherited from Mutant::Isolation
Instance Method Summary collapse
-
#call(&block) ⇒ Object
private
Call block in isolation.
-
#child(reader, writer, &block) ⇒ undefined
private
Handle child process.
-
#parent(reader, writer, &block) ⇒ undefined
private
Handle parent process.
-
#result ⇒ Object
private
The block result computed under silencing.
Instance Method Details
#call(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Call block in isolation
23 24 25 26 27 28 29 |
# File 'lib/mutant/isolation/fork.rb', line 23 def call(&block) io.pipe(binmode: true) do |pipes| parent(*pipes, &block) end rescue => exception raise Error, exception end |
#child(reader, writer, &block) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Handle child process
54 55 56 57 58 59 |
# File 'lib/mutant/isolation/fork.rb', line 54 def child(reader, writer, &block) reader.close writer.binmode writer.syswrite(marshal.dump(result(&block))) writer.close end |
#parent(reader, writer, &block) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Handle parent process
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mutant/isolation/fork.rb', line 37 def parent(reader, writer, &block) pid = process.fork do child(reader, writer, &block) end writer.close marshal.load(reader) ensure process.waitpid(pid) if pid end |
#result ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The block result computed under silencing
64 65 66 67 68 69 70 |
# File 'lib/mutant/isolation/fork.rb', line 64 def result devnull.call do |null| stderr.reopen(null) stdout.reopen(null) yield end end |