Class: SimpleCov::ParallelAdapters::ParallelTestsAdapter

Inherits:
Base
  • Object
show all
Defined in:
lib/simplecov/parallel_adapters/parallel_tests.rb,
sig/simplecov.rbs

Overview

Adapter for grosser/parallel_tests. Requires the full native coordination contract (ParallelTests constant loaded, TEST_ENV_NUMBER and PARALLEL_PID_FILE set); env-var-only setups fall through to GenericAdapter.

Class Method Summary collapse

Class Method Details

.active?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 18

def active?
  return false if SimpleCov.parallel_tests == false

  ensure_loaded
  # !! to coerce `defined?` (returns nil or "constant") to a proper bool.
  !!(defined?(::ParallelTests) && native_parallel_tests_environment?)
end

.ensure_loadedvoid

This method returns an undefined value.

Auto-requires parallel_tests when installed and the env vars it sets are present; a missing gem is treated as "not using parallel_tests" (see issue #1018).



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 68

def ensure_loaded
  return if defined?(::ParallelTests) # simplecov:disable — only true after a previous load
  return if SimpleCov.parallel_tests == false # simplecov:disable — only fires when user opts out
  # simplecov:disable — env-var-only path
  return unless SimpleCov.parallel_tests || env_suggests_parallel_tests?

  # simplecov:disable — only fires under a real parallel_tests setup
  require "parallel_tests"
rescue LoadError
  # Gem isn't installed; stay quiet — warning here regressed
  # users who use those env vars for their own subprocess
  # coordination.
  # simplecov:enable
end

.env_suggests_parallel_tests?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 83

def env_suggests_parallel_tests?
  ENV.key?("TEST_ENV_NUMBER") && ENV.key?("PARALLEL_TEST_GROUPS")
end

.expected_worker_countInteger

Returns:

  • (Integer)


52
53
54
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 52

def expected_worker_count
  ENV["PARALLEL_TEST_GROUPS"]&.to_i || 1
end

.first_worker?Boolean

Delegates to ParallelTests.first_process? (the first started process does the final-result work; see issue #922).

Returns:

  • (Boolean)


36
37
38
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 36

def first_worker?
  ::ParallelTests.first_process?
end

.native_parallel_tests_environment?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 87

def native_parallel_tests_environment?
  ENV.key?("TEST_ENV_NUMBER") && ENV.key?("PARALLEL_PID_FILE")
end

.native_wait?Boolean

The native wait blocks until every sibling process exits, but only when the pid-file contract is present (see wait_for_siblings).

Returns:

  • (Boolean)


48
49
50
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 48

def native_wait?
  native_parallel_tests_environment?
end

.wait_for_siblingsvoid

This method returns an undefined value.

Uses ParallelTests.wait_for_other_processes_to_finish when the pid-file contract is present.



1596
1597
1598
1599
1600
# File 'sig/simplecov.rbs', line 1596

def wait_for_siblings
  return unless native_parallel_tests_environment?

  ::ParallelTests.wait_for_other_processes_to_finish
end