Class: Henitai::Integration::RspecProcessRunner

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

Overview

Runs RSpec child and suite processes on behalf of the integration.

Instance Method Summary collapse

Instance Method Details

#run_mutant(integration, mutant:, test_files:, timeout:) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/henitai/integration/rspec_process_runner.rb', line 59

def run_mutant(integration, mutant:, test_files:, timeout:)
  handle = integration.spawn_mutant(mutant:, test_files:)
  SchedulerDiagnostics.child_started(handle.pid)
  wait_result = integration.wait_with_timeout(handle.pid, timeout)
  integration.build_result(wait_result, handle.log_paths)
ensure
  SchedulerDiagnostics.child_ended(handle&.pid)
  finalize_mutant_run(integration, handle&.pid, wait_result)
end

#run_suite(integration, test_files, timeout:) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/henitai/integration/rspec_process_runner.rb', line 69

def run_suite(integration, test_files, timeout:)
  log_paths = integration.scenario_log_paths("baseline")
  wait_result = nil
  FileUtils.mkdir_p(File.dirname(log_paths[:stdout_path]))
  pid = integration.spawn_suite_process(test_files, log_paths)
  wait_result = integration.wait_with_timeout(pid, timeout)
  integration.build_result(wait_result, log_paths)
ensure
  if pid
    integration.cleanup_process_group(pid) unless wait_result == :timeout
    integration.reap_child(pid) if wait_result.nil?
  end
end

#spawn_mutant(integration, mutant:, test_files:, log_paths:) ⇒ Object

Called from Integration::Rspec#spawn_mutant (and Minitest#spawn_mutant). Forks a child, sets process group, activates the mutant, runs tests. Returns a ChildHandle with the forked pid and log_paths.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/henitai/integration/rspec_process_runner.rb', line 86

def spawn_mutant(integration, mutant:, test_files:, log_paths:)
  pid = Process.fork do
    Process.setpgid(0, 0)
    ENV["HENITAI_MUTANT_ID"] = mutant.id
    Process.exit(
      integration.run_in_child(
        mutant: mutant,
        test_files: test_files,
        log_paths: log_paths
      )
    )
  end
  ChildHandle.new(pid:, log_paths:)
end