Class: Henitai::Integration::Base

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

Overview

Base class for all integrations.

Direct Known Subclasses

Rspec

Instance Method Summary collapse

Instance Method Details

#cleanup_process_group(pid) ⇒ Object



388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/henitai/integration.rb', line 388

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)


364
365
366
# File 'lib/henitai/integration.rb', line 364

def per_test_coverage_supported?
  false
end

#reap_child(pid) ⇒ Object



382
383
384
385
386
# File 'lib/henitai/integration.rb', line 382

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)


349
350
351
# File 'lib/henitai/integration.rb', line 349

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)


334
335
336
# File 'lib/henitai/integration.rb', line 334

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)


360
361
362
# File 'lib/henitai/integration.rb', line 360

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)


339
340
341
# File 'lib/henitai/integration.rb', line 339

def test_files
  raise NotImplementedError
end

#wait_with_timeout(pid, timeout) ⇒ Object



368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/henitai/integration.rb', line 368

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