Module: SimpleCov::ProcessForkHook

Defined in:
lib/simplecov/process.rb

Overview

Prepended onto Process's singleton class so every fork — direct or via Kernel#fork / IO.popen — re-runs SimpleCov's at_fork callback in the child.

Instance Method Summary collapse

Instance Method Details

#_forkObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/simplecov/process.rb', line 34

def _fork
  active = defined?(SimpleCov) && Coverage.running?
  # Assign the next serial in the PARENT, before the fork, so the child
  # inherits its own stable ordinal via copy-on-write. The default
  # at_fork uses it (instead of the child pid) to name the subprocess's
  # result, keeping that name identical across runs. See issue #1171.
  SimpleCov.next_subprocess_serial! if active
  pid = super
  if pid.zero? && active
    # Mark the child here, independent of whatever custom at_fork block
    # the user installed, so `final_result_process?` can keep forked
    # workers from each producing the final report. See issue #1171.
    SimpleCov.mark_forked_subprocess!
    # Without this, a child forked under Minitest autorun measures
    # coverage and then silently discards it: every inherited exit
    # route is dead in the child (see the method's comment). A custom
    # at_fork runs afterwards and can still override. See issue #1227.
    SimpleCov.reset_inherited_at_exit_state!
    SimpleCov.at_fork.call(::Process.pid)
  end
  pid
end