Module: Polyrun::Data::ParallelProvisioning
- Defined in:
- lib/polyrun/data/parallel_provisioning.rb
Overview
Branching helpers for serial vs **parallel worker** test DB setup (seeds, truncate). Polyrun does not call Rails truncate or load_seed for you — wire those in the callbacks you assign.
Typical split (empty parallel DBs get seeds only; serial run truncates then seeds):
Polyrun::Data::ParallelProvisioning.configure do |c|
c.serial { replant_and_load_seed }
c.parallel_worker { load_seed_only }
end
# In spec_helper after configure:
Polyrun::Data::ParallelProvisioning.run_suite_hooks!
Or use RSpec.install_parallel_provisioning! (+before(:suite)+) or Minitest.install_parallel_provisioning! (require polyrun/minitest from test/test_helper.rb).
Defined Under Namespace
Classes: Configuration
Class Method Summary collapse
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
-
.parallel_workers? ⇒ Boolean
True when multiple shards are in use (Polyrun::Database::Shard sets
POLYRUN_SHARD_TOTAL). - .reset_configuration! ⇒ Object
-
.run_suite_hooks! ⇒ Object
Runs
parallel_worker_hookwhen #parallel_workers?, elseserial_hook. -
.shard_index ⇒ Object
0-based worker index; prefers
POLYRUN_SHARD_INDEX, else derives fromTEST_ENV_NUMBER(parallel_tests). - .shard_total ⇒ Object
Class Method Details
.configuration ⇒ Object
47 48 49 |
# File 'lib/polyrun/data/parallel_provisioning.rb', line 47 def configuration STORAGE.configuration end |
.configure {|configuration| ... } ⇒ Object
43 44 45 |
# File 'lib/polyrun/data/parallel_provisioning.rb', line 43 def configure yield configuration end |
.parallel_workers? ⇒ Boolean
True when multiple shards are in use (Polyrun::Database::Shard sets POLYRUN_SHARD_TOTAL).
56 57 58 |
# File 'lib/polyrun/data/parallel_provisioning.rb', line 56 def parallel_workers? shard_total > 1 end |
.reset_configuration! ⇒ Object
51 52 53 |
# File 'lib/polyrun/data/parallel_provisioning.rb', line 51 def reset_configuration! STORAGE.configuration = Configuration.new end |
.run_suite_hooks! ⇒ Object
Runs parallel_worker_hook when #parallel_workers?, else serial_hook. No-op if the chosen hook is nil.
83 84 85 86 87 88 89 |
# File 'lib/polyrun/data/parallel_provisioning.rb', line 83 def run_suite_hooks! if parallel_workers? configuration.parallel_worker_hook&.call else configuration.serial_hook&.call end end |
.shard_index ⇒ Object
0-based worker index; prefers POLYRUN_SHARD_INDEX, else derives from TEST_ENV_NUMBER (parallel_tests).
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/polyrun/data/parallel_provisioning.rb', line 61 def shard_index if (s = ENV["POLYRUN_SHARD_INDEX"]) && !s.to_s.empty? Integer(s) elsif (n = ENV["TEST_ENV_NUMBER"]).to_s.empty? || n == "0" 0 else Integer(n) - 1 end rescue ArgumentError 0 end |
.shard_total ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/polyrun/data/parallel_provisioning.rb', line 73 def shard_total t = ENV["POLYRUN_SHARD_TOTAL"] return Integer(t) if t && !t.to_s.empty? 1 rescue ArgumentError 1 end |