Class: Henitai::ProcessWorkerRunner

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

Overview

Flat, single-threaded process-slot scheduler for parallel mutation runs.

Owns the process table: it is the sole caller of Process.wait* so there are no race conditions between threads reaping the same child.

Defined Under Namespace

Classes: Runtime, Slot

Constant Summary collapse

PROCESS_DRAIN_WINDOW =

rubocop:disable Metrics/ClassLength

0.2

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ProcessWorkerRunner.



41
42
43
44
45
46
# File 'lib/henitai/process_worker_runner.rb', line 41

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

Instance Method Details

#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.



50
51
52
53
# File 'lib/henitai/process_worker_runner.rb', line 50

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:



63
64
65
66
67
68
69
70
71
72
# File 'lib/henitai/process_worker_runner.rb', line 63

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
  @results
ensure
  @wakeup&.close
  @wakeup = nil
end