Class: Henitai::ProcessWorkerRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/henitai/process_worker_runner.rb

Overview

Flat, single-threaded driver for parallel mutation runs.

Owns the event loop and OS signal handling, and delegates the slot lifecycle (spawning, reaping, timeout detection and the drain/broadcast state machine) to a SlotScheduler. Because the scheduler is the sole caller of Process.wait*, there are no races between threads reaping the same child.

Defined Under Namespace

Classes: Runtime

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker_count:, runtime: Runtime.new, wakeup: nil) ⇒ ProcessWorkerRunner

Returns a new instance of ProcessWorkerRunner.



38
39
40
41
42
43
# File 'lib/henitai/process_worker_runner.rb', line 38

def initialize(worker_count:, runtime: Runtime.new, wakeup: nil)
  @worker_count = worker_count
  @runtime = runtime
  @wakeup = wakeup
  @shutdown_requested = false
end

Instance Attribute Details

#runtimeObject (readonly)

Loop primitives the SlotScheduler reads back from its host.



36
37
38
# File 'lib/henitai/process_worker_runner.rb', line 36

def runtime
  @runtime
end

#wakeupObject (readonly)

Loop primitives the SlotScheduler reads back from its host.



36
37
38
# File 'lib/henitai/process_worker_runner.rb', line 36

def wakeup
  @wakeup
end

#worker_countObject (readonly)

Loop primitives the SlotScheduler reads back from its host.



36
37
38
# File 'lib/henitai/process_worker_runner.rb', line 36

def worker_count
  @worker_count
end

Instance Method Details

#flaky_retry_countObject

Number of mutants that required at least one retry during the run. Mirrors the linear path’s per-mutant flaky semantics so the engine can report a single, mode-agnostic flaky statistic.



48
49
50
# File 'lib/henitai/process_worker_runner.rb', line 48

def flaky_retry_count
  @scheduler ? @scheduler.flaky_retry_count : 0
end

#request_shutdownObject

Trigger a graceful shutdown from outside the event loop. Safe to call from any thread. The loop observes the flag on its next tick.



59
60
61
62
# File 'lib/henitai/process_worker_runner.rb', line 59

def request_shutdown
  @shutdown_requested = true
  @wakeup&.signal
end

#run(mutants, integration, config, progress_reporter, options = {}) ⇒ Array<ScenarioExecutionResult>

Runs all mutants and returns an array of ScenarioExecutionResult.

Parameters:

Returns:



72
73
74
75
76
77
78
79
80
81
# File 'lib/henitai/process_worker_runner.rb', line 72

def run(mutants, integration, config, progress_reporter, options = {})
  Integration::SchedulerDiagnostics.reset! if Integration::SchedulerDiagnostics.enabled?
  prepare_run(mutants, integration, config, progress_reporter, options)

  event_loop
  @scheduler.results
ensure
  @wakeup&.close
  @wakeup = nil
end

#shutdown_requested?Boolean

True once a graceful shutdown has been requested; read by the scheduler.

Returns:

  • (Boolean)


53
54
55
# File 'lib/henitai/process_worker_runner.rb', line 53

def shutdown_requested?
  @shutdown_requested
end