Class: SimpleCov::ParallelAdapters::ParallelTestsAdapter
- Defined in:
- lib/simplecov/parallel_adapters/parallel_tests.rb
Overview
Adapter for [grosser/parallel_tests](github.com/grosser/parallel_tests). This is the historical default — SimpleCov has special-cased parallel_tests since 0.18 — and remains the most precise option for projects on it. Detection is the standard pair: the ‘ParallelTests` constant has been loaded AND `TEST_ENV_NUMBER` is set. The gem itself is autoloaded lazily on first `active?` check so users who don’t have it installed see no warnings (see #1018).
Class Method Summary collapse
- .active? ⇒ Boolean
-
.ensure_loaded ⇒ Object
Auto-require ‘parallel_tests` when it’s installed AND the env vars it sets are present, so callers can rely on ‘defined?(::ParallelTests)` downstream.
- .env_suggests_parallel_tests? ⇒ Boolean
- .expected_worker_count ⇒ Object
-
.first_worker? ⇒ Boolean
Pick the first started process to do the final-result work, not the last.
- .wait_for_siblings ⇒ Object
Class Method Details
.active? ⇒ Boolean
16 17 18 19 20 |
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 16 def active? ensure_loaded # !! to coerce `defined?` (returns nil or "constant") to a proper bool. !!(defined?(::ParallelTests) && ENV.key?("TEST_ENV_NUMBER")) end |
.ensure_loaded ⇒ Object
Auto-require ‘parallel_tests` when it’s installed AND the env vars it sets are present, so callers can rely on ‘defined?(::ParallelTests)` downstream. parallel_tests is an optional dependency (see github.com/grosser/parallel_tests/issues/772), and `TEST_ENV_NUMBER` / `PARALLEL_TEST_GROUPS` are commonly set for other reasons (custom subprocess coordination, CI sharding, the parallel_rspec gem which intentionally mirrors the env-var convention), so a missing gem is treated as “user isn’t using parallel_tests” — silently skip and let GenericAdapter handle it. Users who want to override the auto-detect can set ‘SimpleCov.parallel_tests true` (force on) or `false` (force off). See #1018.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 56 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
71 72 73 |
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 71 def env_suggests_parallel_tests? ENV.key?("TEST_ENV_NUMBER") && ENV.key?("PARALLEL_TEST_GROUPS") end |
.expected_worker_count ⇒ Object
40 41 42 |
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 40 def expected_worker_count ENV["PARALLEL_TEST_GROUPS"]&.to_i || 1 end |
.first_worker? ⇒ Boolean
Pick the first started process to do the final-result work, not the last. The parallel_tests README recommends ‘first_process?` for “do something once after every worker finishes” hooks, so user code that has its own `wait_for_other_processes_to_finish` in an `RSpec.after(:suite)` overwhelmingly waits in the first process — picking the same side avoids the cross-process deadlock #922 reported. Also handles `PARALLEL_TEST_GROUPS=1` naturally (the only worker’s ‘TEST_ENV_NUMBER` is “” and `first_process?` tests for that empty string).
32 33 34 |
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 32 def first_worker? ::ParallelTests.first_process? end |
.wait_for_siblings ⇒ Object
36 37 38 |
# File 'lib/simplecov/parallel_adapters/parallel_tests.rb', line 36 def wait_for_siblings ::ParallelTests.wait_for_other_processes_to_finish end |