Module: SimpleCov::Production
- Defined in:
- lib/simplecov/production.rb,
lib/simplecov/production/error.rb,
lib/simplecov/production/file_sink.rb,
sig/simplecov.rbs,
sig/simplecov.rbs
Defined Under Namespace
Modules: _Sink Classes: Error, FileSink
Class Method Summary collapse
-
.flush ⇒ Boolean
Called by the flush thread every interval; public so a deploy hook (or a signal handler) can force one.
-
.reset! ⇒ void
registration flag survives on purpose: one hook per process.
-
.running? ⇒ Boolean
Both are small Integers, so identity settles it: a measurement belongs to the process that started it and to no other.
-
.start(root: Dir.pwd, sink: nil, flush_interval: 60, flush_jitter: nil, sample_rate: 1.0, max_buffered_lines: 1_000_000) ⇒ Object
Answers false, with a warning naming why, when it safely declines (already running, another Coverage owner such as a test suite, or a runtime without oneshot lines).
- .stop ⇒ Boolean
Class Method Details
.flush ⇒ Boolean
Called by the flush thread every interval; public so a deploy hook (or a signal handler) can force one. An empty delta counts as accepted.
48 49 50 51 52 53 54 55 |
# File 'lib/simplecov/production.rb', line 48 def flush return false unless running? @mutex.synchronize do pull_pending push_pending end end |
.reset! ⇒ void
This method returns an undefined value.
registration flag survives on purpose: one hook per process.
73 74 75 76 77 78 79 80 81 |
# File 'lib/simplecov/production.rb', line 73 def reset! @running = false wake_flush_thread if @thread @thread&.join @thread = nil @pending = {} @pid = nil @started_coverage = false end |
.running? ⇒ Boolean
Both are small Integers, so identity settles it: a measurement belongs to the process that started it and to no other.
42 43 44 |
# File 'lib/simplecov/production.rb', line 42 def running? !!@running && @pid.equal?(Process.pid) end |
.start(root: Dir.pwd, sink: nil, flush_interval: 60, flush_jitter: nil, sample_rate: 1.0, max_buffered_lines: 1_000_000) ⇒ Object
Answers false, with a warning naming why, when it safely declines
(already running, another Coverage owner such as a test suite, or a
runtime without oneshot lines). Configuration mistakes raise Error
instead: a typo'd interval should fail deployment, not quietly measure
wrong.
In a forking server, call this from the worker-boot hook (Puma's
on_worker_boot, Unicorn's after_fork): the flush thread does not
survive a fork, and start in the child picks the inherited
measurement back up.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/simplecov/production.rb', line 25 def start(root: Dir.pwd, sink: nil, flush_interval: 60, flush_jitter: nil, sample_rate: 1.0, max_buffered_lines: 1_000_000) validate!(flush_interval, flush_jitter, sample_rate, max_buffered_lines) return warn_decline("SimpleCov::Production is already running") if running? return false unless claim_coverage configure(root, sink, flush_interval: flush_interval, flush_jitter: flush_jitter, sample_rate: sample_rate, max_buffered_lines: max_buffered_lines) @running = true @pid = Process.pid install_at_exit spawn_flush_thread true end |
.stop ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/simplecov/production.rb', line 57 def stop return false unless running? @running = false wake_flush_thread @thread&.join @mutex.synchronize do pull_pending push_pending Coverage.result(stop: true, clear: true) end true end |