Module: SimpleCov::RunIdentity
- Defined in:
- lib/simplecov/run_identity.rb
Overview
Identifies one test invocation and each top-level parallel worker within it. Forked subprocesses inherit both values from their parent worker.
Defined Under Namespace
Modules: Accessors
Class Method Summary collapse
-
.authoritative? ⇒ Boolean
Whether the current run id alone proves same-run membership.
- .current ⇒ Object
- .current_worker_id ⇒ Object
-
.generate ⇒ Object
Returns the run id together with its provenance:
truewhen the id alone proves same-run membership (explicitly configured, derived from parallel_tests' per-invocation pid file, or freshly random),falsewhen it was inferred from the parent pid, which consecutive runs launched by the same long-lived parent process share. - .materialize_current ⇒ Object
- .prepare ⇒ Object
- .worker_id ⇒ Object
Class Method Details
.authoritative? ⇒ Boolean
Whether the current run id alone proves same-run membership. Decided where the id is generated, never re-inferred from the id's shape, so an explicit SIMPLECOV_RUN_ID that happens to look like an inferred one is still trusted.
42 43 44 45 |
# File 'lib/simplecov/run_identity.rb', line 42 def materialize_current @authoritative end |
.current ⇒ Object
47 48 49 50 |
# File 'lib/simplecov/run_identity.rb', line 47 def current materialize_current @current end |
.current_worker_id ⇒ Object
56 57 58 |
# File 'lib/simplecov/run_identity.rb', line 56 def current_worker_id @current_worker_id ||= worker_id end |
.generate ⇒ Object
Returns the run id together with its provenance: true when the id
alone proves same-run membership (explicitly configured, derived from
parallel_tests' per-invocation pid file, or freshly random), false
when it was inferred from the parent pid, which consecutive runs
launched by the same long-lived parent process share.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/simplecov/run_identity.rb', line 16 def generate explicit = ENV.fetch("SIMPLECOV_RUN_ID", nil) return [explicit, true] if explicit && !explicit.empty? pid_file = ENV.fetch("PARALLEL_PID_FILE", nil) return ["parallel-tests:#{File.basename(pid_file)}", true] if pid_file && !pid_file.empty? return ["parallel-parent:#{Process.ppid}", false] if SimpleCov::ParallelAdapters.current [SecureRandom.uuid, true] end |
.materialize_current ⇒ Object
52 53 54 |
# File 'lib/simplecov/run_identity.rb', line 52 def materialize_current @current, @authoritative = generate unless defined?(@current) end |
.prepare ⇒ Object
60 61 62 63 64 |
# File 'lib/simplecov/run_identity.rb', line 60 def prepare SimpleCov::ParallelAdapters.current SimpleCov.run_id SimpleCov.worker_id end |
.worker_id ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/simplecov/run_identity.rb', line 28 def worker_id explicit = ENV.fetch("SIMPLECOV_WORKER_ID", nil) return explicit if explicit && !explicit.empty? number = ENV.fetch("TEST_ENV_NUMBER", nil) return number.empty? ? "1" : number if number Process.pid.to_s end |