Class: Henitai::Integration::Base

Inherits:
Object
  • Object
show all
Includes:
ChildDebugSupport, ChildRuntimeControl
Defined in:
lib/henitai/integration/base.rb

Overview

Base class for all integrations. Provides the framework-agnostic child process lifecycle (wait, timeout handling, cleanup) and subprocess environment helpers. Concrete adapters mix in MutantRunSupport and implement #run_tests plus test selection.

Direct Known Subclasses

Minitest, Rspec

Instance Method Summary collapse

Instance Method Details

#cleanup_process_group(pid) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/henitai/integration/base.rb', line 75

def cleanup_process_group(pid)
  grace_period = 2.0
  wakeup = Henitai.const_get(:ProcessWakeup).new.install
  Process.kill(:SIGTERM, -pid)
  return if wait_nonblocking(pid)

  wakeup.wait(grace_period)
  wakeup.drain
  return if wait_nonblocking(pid)

  Process.kill(:SIGKILL, -pid)
rescue Errno::EPERM
  cleanup_child_process(pid)
rescue Errno::ESRCH
  nil
ensure
  wakeup&.close
end

#per_test_coverage_supported?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/henitai/integration/base.rb', line 51

def per_test_coverage_supported?
  false
end

#reap_child(pid) ⇒ Object



69
70
71
72
73
# File 'lib/henitai/integration/base.rb', line 69

def reap_child(pid)
  Process.wait(pid)
rescue Errno::ECHILD, Errno::ESRCH
  nil
end

#run_mutant(mutant:, test_files:, timeout:) ⇒ ScenarioExecutionResult

Run test files in a child process with the mutant active.

Parameters:

  • mutant (Mutant)
  • test_files (Array<String>)
  • timeout (Float)

    seconds

Returns:

Raises:

  • (NotImplementedError)


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

def run_mutant(mutant:, test_files:, timeout:)
  raise NotImplementedError
end

#select_tests(subject) ⇒ Array<String>

Returns paths to test files that cover this subject.

Parameters:

Returns:

  • (Array<String>)

    paths to test files that cover this subject

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/henitai/integration/base.rb', line 21

def select_tests(subject)
  raise NotImplementedError
end

#spawn_mutant(mutant:, test_files:) ⇒ RspecProcessRunner::ChildHandle

Fork a child process for the mutant without waiting for it to finish. Returns a ChildHandle carrying the OS pid and log file paths. The caller is responsible for waiting and cleanup.

Parameters:

  • mutant (Mutant)
  • test_files (Array<String>)

Returns:

  • (RspecProcessRunner::ChildHandle)

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/henitai/integration/base.rb', line 47

def spawn_mutant(mutant:, test_files:)
  raise NotImplementedError
end

#test_filesArray<String>

Returns all test files for the configured framework.

Returns:

  • (Array<String>)

    all test files for the configured framework

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/henitai/integration/base.rb', line 26

def test_files
  raise NotImplementedError
end

#wait_with_timeout(pid, timeout) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/henitai/integration/base.rb', line 55

def wait_with_timeout(pid, timeout)
  wakeup = Henitai.const_get(:ProcessWakeup).new.install
  return Process.last_status if wait_nonblocking(pid)

  wakeup.wait(timeout)
  wakeup.drain
  return Process.last_status if wait_nonblocking(pid)
  return Process.last_status if wait_nonblocking(pid)

  handle_timeout(pid)
ensure
  wakeup&.close
end