polyrun 3.2.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +234 -0
- data/CODE_OF_CONDUCT.md +26 -0
- data/CONTRIBUTING.md +23 -0
- data/LICENSE +21 -0
- data/README.md +251 -0
- data/SECURITY.md +25 -0
- data/bin/polyrun +6 -0
- data/docs/QUALITY.md +82 -0
- data/docs/QUALITY_CONFIGURATION.md +95 -0
- data/docs/SETUP_PROFILE.md +139 -0
- data/lib/polyrun/benchmark/pressure/cooker.rb +191 -0
- data/lib/polyrun/benchmark/pressure/process_sample.rb +127 -0
- data/lib/polyrun/benchmark/pressure.rb +144 -0
- data/lib/polyrun/benchmark/profile.rb +191 -0
- data/lib/polyrun/benchmark/report.rb +87 -0
- data/lib/polyrun/cli/benchmark_commands.rb +66 -0
- data/lib/polyrun/cli/ci_shard_hooks.rb +129 -0
- data/lib/polyrun/cli/ci_shard_run_command.rb +177 -0
- data/lib/polyrun/cli/ci_shard_run_parse.rb +68 -0
- data/lib/polyrun/cli/config_command.rb +42 -0
- data/lib/polyrun/cli/coverage_commands.rb +150 -0
- data/lib/polyrun/cli/coverage_merge_io.rb +150 -0
- data/lib/polyrun/cli/database_commands.rb +163 -0
- data/lib/polyrun/cli/default_run.rb +144 -0
- data/lib/polyrun/cli/doctor_command.rb +94 -0
- data/lib/polyrun/cli/env_commands.rb +43 -0
- data/lib/polyrun/cli/failure_commands.rb +99 -0
- data/lib/polyrun/cli/graph_command.rb +68 -0
- data/lib/polyrun/cli/help.rb +83 -0
- data/lib/polyrun/cli/helpers.rb +162 -0
- data/lib/polyrun/cli/hooks_command.rb +97 -0
- data/lib/polyrun/cli/init_command.rb +108 -0
- data/lib/polyrun/cli/mutation_command.rb +67 -0
- data/lib/polyrun/cli/partition_diagnostics.rb +22 -0
- data/lib/polyrun/cli/plan_command.rb +184 -0
- data/lib/polyrun/cli/prepare_command.rb +70 -0
- data/lib/polyrun/cli/prepare_recipe.rb +82 -0
- data/lib/polyrun/cli/quality_commands.rb +65 -0
- data/lib/polyrun/cli/queue_command.rb +161 -0
- data/lib/polyrun/cli/quick_command.rb +13 -0
- data/lib/polyrun/cli/report_commands.rb +108 -0
- data/lib/polyrun/cli/run_queue_command.rb +127 -0
- data/lib/polyrun/cli/run_shards_command.rb +164 -0
- data/lib/polyrun/cli/run_shards_parallel_children.rb +112 -0
- data/lib/polyrun/cli/run_shards_parallel_wait.rb +252 -0
- data/lib/polyrun/cli/run_shards_plan_boot_phases.rb +207 -0
- data/lib/polyrun/cli/run_shards_plan_options.rb +74 -0
- data/lib/polyrun/cli/run_shards_planning.rb +123 -0
- data/lib/polyrun/cli/run_shards_run.rb +171 -0
- data/lib/polyrun/cli/run_shards_worker_interrupt.rb +101 -0
- data/lib/polyrun/cli/skip_env.rb +34 -0
- data/lib/polyrun/cli/spec_quality_commands.rb +149 -0
- data/lib/polyrun/cli/start_bootstrap.rb +126 -0
- data/lib/polyrun/cli/timing_command.rb +31 -0
- data/lib/polyrun/cli/tool_options.rb +48 -0
- data/lib/polyrun/cli/validate_command.rb +26 -0
- data/lib/polyrun/cli.rb +272 -0
- data/lib/polyrun/config/dotted_path.rb +21 -0
- data/lib/polyrun/config/effective.rb +82 -0
- data/lib/polyrun/config/resolver.rb +114 -0
- data/lib/polyrun/config/schema.rb +39 -0
- data/lib/polyrun/config/suite.rb +109 -0
- data/lib/polyrun/config/tool_defaults.rb +42 -0
- data/lib/polyrun/config/tool_validation.rb +79 -0
- data/lib/polyrun/config/tools.rb +120 -0
- data/lib/polyrun/config.rb +97 -0
- data/lib/polyrun/coverage/cobertura_zero_lines.rb +32 -0
- data/lib/polyrun/coverage/collector.rb +169 -0
- data/lib/polyrun/coverage/collector_blob.rb +53 -0
- data/lib/polyrun/coverage/collector_finish.rb +98 -0
- data/lib/polyrun/coverage/collector_fragment_meta.rb +57 -0
- data/lib/polyrun/coverage/config_resolve.rb +131 -0
- data/lib/polyrun/coverage/example_diff.rb +184 -0
- data/lib/polyrun/coverage/example_diff_snapshot.rb +44 -0
- data/lib/polyrun/coverage/example_diff_track_filter.rb +51 -0
- data/lib/polyrun/coverage/file_stats_report.rb +36 -0
- data/lib/polyrun/coverage/filter.rb +22 -0
- data/lib/polyrun/coverage/formatter.rb +137 -0
- data/lib/polyrun/coverage/merge/formatters.rb +188 -0
- data/lib/polyrun/coverage/merge/formatters_html.rb +221 -0
- data/lib/polyrun/coverage/merge/html/_file_list.html.erb +21 -0
- data/lib/polyrun/coverage/merge/html/_file_section.html.erb +26 -0
- data/lib/polyrun/coverage/merge/html/_groups_table.html.erb +18 -0
- data/lib/polyrun/coverage/merge/html/_overview.html.erb +47 -0
- data/lib/polyrun/coverage/merge/html/report.css +147 -0
- data/lib/polyrun/coverage/merge/html/report.js +48 -0
- data/lib/polyrun/coverage/merge/html/template.html.erb +30 -0
- data/lib/polyrun/coverage/merge.rb +160 -0
- data/lib/polyrun/coverage/merge_fragment_meta.rb +58 -0
- data/lib/polyrun/coverage/merge_merge_two.rb +168 -0
- data/lib/polyrun/coverage/merge_native.rb +39 -0
- data/lib/polyrun/coverage/rails.rb +126 -0
- data/lib/polyrun/coverage/reporting.rb +41 -0
- data/lib/polyrun/coverage/result.rb +18 -0
- data/lib/polyrun/coverage/track_files.rb +150 -0
- data/lib/polyrun/data/cached_fixtures.rb +122 -0
- data/lib/polyrun/data/factory_counts.rb +48 -0
- data/lib/polyrun/data/factory_instrumentation.rb +50 -0
- data/lib/polyrun/data/fixtures.rb +68 -0
- data/lib/polyrun/data/parallel_provisioning.rb +93 -0
- data/lib/polyrun/data/snapshot.rb +84 -0
- data/lib/polyrun/database/clone_shards.rb +106 -0
- data/lib/polyrun/database/provision.rb +83 -0
- data/lib/polyrun/database/shard.rb +64 -0
- data/lib/polyrun/database/url_builder/connection/infer.rb +53 -0
- data/lib/polyrun/database/url_builder/connection/url_builders.rb +43 -0
- data/lib/polyrun/database/url_builder/connection.rb +191 -0
- data/lib/polyrun/database/url_builder/template_prepare.rb +21 -0
- data/lib/polyrun/database/url_builder.rb +188 -0
- data/lib/polyrun/debug.rb +81 -0
- data/lib/polyrun/env/ci.rb +65 -0
- data/lib/polyrun/error.rb +3 -0
- data/lib/polyrun/export/csv.rb +25 -0
- data/lib/polyrun/export/markdown.rb +47 -0
- data/lib/polyrun/graph/client.rb +64 -0
- data/lib/polyrun/graph/error.rb +13 -0
- data/lib/polyrun/graph/index.rb +75 -0
- data/lib/polyrun/graph/inspect.rb +58 -0
- data/lib/polyrun/graph/plan.rb +134 -0
- data/lib/polyrun/graph/planner.rb +117 -0
- data/lib/polyrun/graph/syntax.rb +114 -0
- data/lib/polyrun/graph/transaction.rb +81 -0
- data/lib/polyrun/graph/worker.rb +55 -0
- data/lib/polyrun/graph/workspace.rb +117 -0
- data/lib/polyrun/hooks/dsl.rb +128 -0
- data/lib/polyrun/hooks/shell_runner.rb +33 -0
- data/lib/polyrun/hooks/worker_runner.rb +27 -0
- data/lib/polyrun/hooks/worker_shell.rb +50 -0
- data/lib/polyrun/hooks.rb +190 -0
- data/lib/polyrun/log.rb +86 -0
- data/lib/polyrun/minitest_support.rb +60 -0
- data/lib/polyrun/mutation/candidates.rb +91 -0
- data/lib/polyrun/mutation/operators.rb +51 -0
- data/lib/polyrun/mutation/runner.rb +133 -0
- data/lib/polyrun/mutation/subjects.rb +88 -0
- data/lib/polyrun/partition/constraints.rb +80 -0
- data/lib/polyrun/partition/hrw.rb +70 -0
- data/lib/polyrun/partition/min_heap.rb +64 -0
- data/lib/polyrun/partition/paths.rb +175 -0
- data/lib/polyrun/partition/paths_build.rb +141 -0
- data/lib/polyrun/partition/plan.rb +250 -0
- data/lib/polyrun/partition/plan_lpt.rb +91 -0
- data/lib/polyrun/partition/plan_sharding.rb +56 -0
- data/lib/polyrun/partition/reports.rb +139 -0
- data/lib/polyrun/partition/stable_shuffle.rb +18 -0
- data/lib/polyrun/partition/suite.rb +120 -0
- data/lib/polyrun/partition/timing_diagnostics.rb +138 -0
- data/lib/polyrun/partition/timing_keys.rb +86 -0
- data/lib/polyrun/prepare/artifacts.rb +40 -0
- data/lib/polyrun/prepare/assets.rb +64 -0
- data/lib/polyrun/process_stdio.rb +96 -0
- data/lib/polyrun/quality/command.rb +84 -0
- data/lib/polyrun/quality/measure.rb +38 -0
- data/lib/polyrun/quality/observe.rb +53 -0
- data/lib/polyrun/quality/observe_hook.rb +103 -0
- data/lib/polyrun/quality/sandbox.rb +70 -0
- data/lib/polyrun/queue/duration.rb +30 -0
- data/lib/polyrun/queue/file_store.rb +413 -0
- data/lib/polyrun/queue/file_store_intent.rb +188 -0
- data/lib/polyrun/queue/file_store_pending.rb +48 -0
- data/lib/polyrun/queue/worker_loop.rb +73 -0
- data/lib/polyrun/quick/assertions.rb +32 -0
- data/lib/polyrun/quick/config.rb +56 -0
- data/lib/polyrun/quick/errors.rb +6 -0
- data/lib/polyrun/quick/example_group.rb +111 -0
- data/lib/polyrun/quick/example_runner.rb +129 -0
- data/lib/polyrun/quick/matchers.rb +159 -0
- data/lib/polyrun/quick/matchers_predicates.rb +122 -0
- data/lib/polyrun/quick/reporter.rb +76 -0
- data/lib/polyrun/quick/runner.rb +224 -0
- data/lib/polyrun/quick.rb +1 -0
- data/lib/polyrun/railtie.rb +7 -0
- data/lib/polyrun/reporting/failure_merge.rb +171 -0
- data/lib/polyrun/reporting/junit.rb +126 -0
- data/lib/polyrun/reporting/junit_emit.rb +58 -0
- data/lib/polyrun/reporting/junit_report.rb +87 -0
- data/lib/polyrun/reporting/rspec_failure_fragment_formatter.rb +95 -0
- data/lib/polyrun/reporting/rspec_junit.rb +39 -0
- data/lib/polyrun/rspec_support/active_record_timeout_recovery.rb +51 -0
- data/lib/polyrun/rspec_support/example_debug.rb +167 -0
- data/lib/polyrun/rspec_support/example_debug_instrumentation.rb +73 -0
- data/lib/polyrun/rspec_support/sharded_formatter_compat.rb +57 -0
- data/lib/polyrun/rspec_support.rb +110 -0
- data/lib/polyrun/spec_quality/config.rb +139 -0
- data/lib/polyrun/spec_quality/fragment.rb +39 -0
- data/lib/polyrun/spec_quality/merge.rb +78 -0
- data/lib/polyrun/spec_quality/minitest_hook.rb +42 -0
- data/lib/polyrun/spec_quality/plan_loader.rb +47 -0
- data/lib/polyrun/spec_quality/profile.rb +102 -0
- data/lib/polyrun/spec_quality/report.rb +363 -0
- data/lib/polyrun/spec_quality/rspec_hook.rb +55 -0
- data/lib/polyrun/spec_quality/sql_counter.rb +34 -0
- data/lib/polyrun/spec_quality.rb +212 -0
- data/lib/polyrun/sus_support.rb +55 -0
- data/lib/polyrun/templates/POLYRUN.md +51 -0
- data/lib/polyrun/templates/ci_matrix.polyrun.yml +22 -0
- data/lib/polyrun/templates/minimal_gem.polyrun.yml +13 -0
- data/lib/polyrun/templates/polyrun_hooks_spec_quality.rb +12 -0
- data/lib/polyrun/templates/polyrun_spec_quality.yml +20 -0
- data/lib/polyrun/templates/rails_prepare.polyrun.yml +51 -0
- data/lib/polyrun/templates/rails_prepare_task.rake +16 -0
- data/lib/polyrun/timing/merge.rb +36 -0
- data/lib/polyrun/timing/rspec_example_formatter.rb +60 -0
- data/lib/polyrun/timing/stats.rb +76 -0
- data/lib/polyrun/timing/summary.rb +78 -0
- data/lib/polyrun/timing/variance_report.rb +51 -0
- data/lib/polyrun/version.rb +3 -0
- data/lib/polyrun/worker_output.rb +181 -0
- data/lib/polyrun/worker_output_forwarders.rb +94 -0
- data/lib/polyrun/worker_ping.rb +77 -0
- data/lib/polyrun.rb +59 -0
- data/polyrun.gemspec +49 -0
- data/sig/polyrun/cli.rbs +6 -0
- data/sig/polyrun/config.rbs +20 -0
- data/sig/polyrun/debug.rbs +12 -0
- data/sig/polyrun/log.rbs +12 -0
- data/sig/polyrun/minitest_support.rbs +7 -0
- data/sig/polyrun/quick.rbs +19 -0
- data/sig/polyrun/rspec_support.rbs +21 -0
- data/sig/polyrun/sus_support.rbs +7 -0
- data/sig/polyrun/worker_output.rbs +11 -0
- data/sig/polyrun/worker_ping.rbs +10 -0
- data/sig/polyrun.rbs +11 -0
- metadata +463 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# rubocop:disable Polyrun/FileLength -- run-shards boot phases A/B
|
|
2
|
+
require "shellwords"
|
|
3
|
+
|
|
4
|
+
module Polyrun
|
|
5
|
+
class CLI
|
|
6
|
+
# Boot argv, then phase A (options + validate) and B (items + plan) for run-shards.
|
|
7
|
+
module RunShardsPlanBootPhases
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
# @return [:fail, Integer] | [:ok, Hash, Array<String>]
|
|
11
|
+
def run_shards_plan_phase_a(head, cmd, pc, cfg = nil)
|
|
12
|
+
o = run_shards_plan_options(head, pc, cfg: cfg)
|
|
13
|
+
code = Polyrun::Partition::PathsBuild.apply!(partition: pc, cwd: Dir.pwd)
|
|
14
|
+
return [:fail, code] if code != 0
|
|
15
|
+
|
|
16
|
+
o[:timing_path] = run_shards_default_timing_path(pc, o[:timing_path], o[:strategy])
|
|
17
|
+
err = run_shards_validate_workers!(o)
|
|
18
|
+
return [:fail, err] if err
|
|
19
|
+
|
|
20
|
+
err = run_shards_validate_cmd(cmd)
|
|
21
|
+
return [:fail, err] if err
|
|
22
|
+
|
|
23
|
+
run_shards_normalize_worker_timeout_option!(o)
|
|
24
|
+
run_shards_normalize_worker_idle_timeout_option!(o)
|
|
25
|
+
|
|
26
|
+
cmd = Shellwords.split(cmd.first) if cmd.size == 1 && cmd.first.include?(" ")
|
|
27
|
+
|
|
28
|
+
[:ok, o, cmd]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# rubocop:disable Metrics/AbcSize -- items + costs + plan emit for run-shards
|
|
32
|
+
def run_shards_plan_phase_b(o, cmd, cfg, pc, run_t0, config_path)
|
|
33
|
+
items, paths_source, err = run_shards_resolve_items(o[:paths_file], pc)
|
|
34
|
+
return [err, nil] if err
|
|
35
|
+
|
|
36
|
+
err = run_shards_validate_suite_vs_command!(items, cmd)
|
|
37
|
+
return [err, nil] if err
|
|
38
|
+
|
|
39
|
+
costs, strategy, err = run_shards_resolve_costs(
|
|
40
|
+
o[:timing_path],
|
|
41
|
+
o[:strategy],
|
|
42
|
+
o[:timing_granularity],
|
|
43
|
+
strategy_explicit: o[:strategy_explicit]
|
|
44
|
+
)
|
|
45
|
+
return [err, nil] if err
|
|
46
|
+
|
|
47
|
+
run_shards_plan_ready_log(o, cfg, strategy, cmd, paths_source, items.size)
|
|
48
|
+
|
|
49
|
+
constraints = load_partition_constraints(pc, o[:constraints_path])
|
|
50
|
+
stable = load_stable_assignment(pc)
|
|
51
|
+
plan = run_shards_make_plan(
|
|
52
|
+
items, o[:workers], strategy, o[:seed], costs, constraints, o[:timing_granularity], stable,
|
|
53
|
+
shard_weights: pc["shard_weights"] || pc[:shard_weights]
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
partition_emit_diagnostics!(
|
|
57
|
+
plan: plan,
|
|
58
|
+
items: items,
|
|
59
|
+
costs: costs,
|
|
60
|
+
timing_path: o[:timing_path],
|
|
61
|
+
granularity: o[:timing_granularity]
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
run_shards_debug_shard_sizes(plan, o[:workers])
|
|
65
|
+
Polyrun::Log.warn "polyrun run-shards: #{items.size} paths → #{o[:workers]} workers (#{strategy})" if @verbose
|
|
66
|
+
|
|
67
|
+
parallel = o[:workers] > 1
|
|
68
|
+
run_shards_warn_parallel_banner(items.size, o[:workers], strategy) if parallel
|
|
69
|
+
|
|
70
|
+
[nil, run_shards_plan_context_hash(o, cmd, cfg, plan, run_t0, parallel, config_path)]
|
|
71
|
+
end
|
|
72
|
+
# rubocop:enable Metrics/AbcSize
|
|
73
|
+
|
|
74
|
+
def run_shards_plan_boot(argv, config_path)
|
|
75
|
+
run_t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
76
|
+
sep = argv.index("--")
|
|
77
|
+
unless sep
|
|
78
|
+
Polyrun::Log.warn "polyrun run-shards: need -- before the command (e.g. run-shards --workers 5 -- bundle exec rspec)"
|
|
79
|
+
return [2, nil]
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
head = argv[0...sep]
|
|
83
|
+
cmd = argv[(sep + 1)..].map(&:to_s)
|
|
84
|
+
cfg = Polyrun::Config.load(path: config_path || ENV["POLYRUN_CONFIG"])
|
|
85
|
+
[run_t0, head, cmd, cfg, cfg.partition]
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def run_shards_plan_ready_log(o, cfg, strategy, cmd, paths_source, item_count)
|
|
89
|
+
Polyrun::Debug.log_kv(
|
|
90
|
+
run_shards: "ready to partition",
|
|
91
|
+
workers: o[:workers],
|
|
92
|
+
strategy: strategy,
|
|
93
|
+
merge_coverage: o[:merge_coverage],
|
|
94
|
+
merge_failures: run_shards_merge_failures_flag(o, cfg),
|
|
95
|
+
merge_spec_quality: run_shards_merge_spec_quality_flag(o, cfg),
|
|
96
|
+
command: cmd,
|
|
97
|
+
timing_path: o[:timing_path],
|
|
98
|
+
paths_source: paths_source,
|
|
99
|
+
item_count: item_count
|
|
100
|
+
)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def run_shards_merge_spec_quality_flag(o, cfg)
|
|
104
|
+
return true if o[:merge_spec_quality]
|
|
105
|
+
return true if %w[1 true yes].include?(ENV["POLYRUN_MERGE_SPEC_QUALITY"].to_s.downcase)
|
|
106
|
+
|
|
107
|
+
rep = cfg.reporting
|
|
108
|
+
v = rep["merge_spec_quality"] || rep[:merge_spec_quality]
|
|
109
|
+
v == true || %w[1 true yes].include?(v.to_s.downcase)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def run_shards_merge_spec_quality_output_opt(o, cfg)
|
|
113
|
+
x = o[:merge_spec_quality_output]
|
|
114
|
+
return x if x && !x.to_s.strip.empty?
|
|
115
|
+
|
|
116
|
+
x = ENV["POLYRUN_MERGED_SPEC_QUALITY_OUT"]
|
|
117
|
+
return x if x && !x.to_s.strip.empty?
|
|
118
|
+
|
|
119
|
+
rep = cfg.reporting
|
|
120
|
+
rep["merge_spec_quality_output"] || rep[:merge_spec_quality_output]
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def run_shards_merge_failures_flag(o, cfg)
|
|
124
|
+
return true if o[:merge_failures]
|
|
125
|
+
return true if %w[1 true yes].include?(ENV["POLYRUN_MERGE_FAILURES"].to_s.downcase)
|
|
126
|
+
|
|
127
|
+
rep = cfg.reporting
|
|
128
|
+
v = rep["merge_failures"] || rep[:merge_failures]
|
|
129
|
+
v == true || %w[1 true yes].include?(v.to_s.downcase)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def run_shards_merge_failures_output_opt(o, cfg)
|
|
133
|
+
x = o[:merge_failures_output]
|
|
134
|
+
return x if x && !x.to_s.strip.empty?
|
|
135
|
+
|
|
136
|
+
x = ENV["POLYRUN_MERGED_FAILURES_OUT"]
|
|
137
|
+
return x if x && !x.to_s.strip.empty?
|
|
138
|
+
|
|
139
|
+
rep = cfg.reporting
|
|
140
|
+
rep["merge_failures_output"] || rep[:merge_failures_output]
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def run_shards_merge_failures_format_opt(o, cfg)
|
|
144
|
+
x = o[:merge_failures_format]
|
|
145
|
+
return x if x && !x.to_s.strip.empty?
|
|
146
|
+
|
|
147
|
+
x = ENV["POLYRUN_MERGED_FAILURES_FORMAT"]
|
|
148
|
+
return x if x && !x.to_s.strip.empty?
|
|
149
|
+
|
|
150
|
+
rep = cfg.reporting
|
|
151
|
+
rep["merge_failures_format"] || rep[:merge_failures_format]
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def run_shards_plan_context_hash(o, cmd, cfg, plan, run_t0, parallel, config_path)
|
|
155
|
+
{
|
|
156
|
+
workers: o[:workers],
|
|
157
|
+
cmd: cmd,
|
|
158
|
+
cfg: cfg,
|
|
159
|
+
plan: plan,
|
|
160
|
+
run_t0: run_t0,
|
|
161
|
+
parallel: parallel,
|
|
162
|
+
merge_coverage: o[:merge_coverage],
|
|
163
|
+
merge_output: o[:merge_output],
|
|
164
|
+
merge_format: o[:merge_format],
|
|
165
|
+
merge_failures: run_shards_merge_failures_flag(o, cfg),
|
|
166
|
+
merge_failures_output: run_shards_merge_failures_output_opt(o, cfg),
|
|
167
|
+
merge_failures_format: run_shards_merge_failures_format_opt(o, cfg),
|
|
168
|
+
merge_spec_quality: run_shards_merge_spec_quality_flag(o, cfg),
|
|
169
|
+
merge_spec_quality_output: run_shards_merge_spec_quality_output_opt(o, cfg),
|
|
170
|
+
report_spec_quality: o[:report_spec_quality] != false,
|
|
171
|
+
config_path: config_path,
|
|
172
|
+
worker_timeout_sec: run_shards_resolved_worker_timeout_sec(o),
|
|
173
|
+
worker_idle_timeout_sec: run_shards_resolved_worker_idle_timeout_sec(o)
|
|
174
|
+
}
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def run_shards_normalize_worker_idle_timeout_option!(o)
|
|
178
|
+
v = o[:worker_idle_timeout_sec]
|
|
179
|
+
return if v.nil?
|
|
180
|
+
|
|
181
|
+
o[:worker_idle_timeout_sec] = nil if v <= 0
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def run_shards_resolved_worker_idle_timeout_sec(o)
|
|
185
|
+
cli = o[:worker_idle_timeout_sec]
|
|
186
|
+
return cli.to_f if cli.is_a?(Numeric) && cli > 0
|
|
187
|
+
|
|
188
|
+
env_worker_idle_timeout_sec
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def run_shards_normalize_worker_timeout_option!(o)
|
|
192
|
+
v = o[:worker_timeout_sec]
|
|
193
|
+
return if v.nil?
|
|
194
|
+
|
|
195
|
+
o[:worker_timeout_sec] = nil if v <= 0
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def run_shards_resolved_worker_timeout_sec(o)
|
|
199
|
+
cli = o[:worker_timeout_sec]
|
|
200
|
+
return cli.to_f if cli.is_a?(Numeric) && cli > 0
|
|
201
|
+
|
|
202
|
+
env_worker_timeout_sec
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
# rubocop:enable Polyrun/FileLength
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require "optparse"
|
|
2
|
+
|
|
3
|
+
module Polyrun
|
|
4
|
+
class CLI
|
|
5
|
+
module RunShardsPlanOptions
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def run_shards_plan_options(head, pc, cfg: nil)
|
|
9
|
+
st = run_shards_plan_options_state(pc, cfg: cfg)
|
|
10
|
+
run_shards_plan_options_parse!(head, st)
|
|
11
|
+
st[:paths_file] ||= pc["paths_file"] || pc[:paths_file]
|
|
12
|
+
st[:timing_granularity] = resolve_partition_timing_granularity(pc, st[:timing_granularity])
|
|
13
|
+
st
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def run_shards_plan_options_state(pc, cfg: nil)
|
|
17
|
+
{
|
|
18
|
+
workers: Polyrun::Config::Resolver.parallel_worker_count(cfg),
|
|
19
|
+
paths_file: nil,
|
|
20
|
+
strategy: (pc["strategy"] || pc[:strategy] || "round_robin").to_s,
|
|
21
|
+
strategy_explicit: !!(pc["strategy"] || pc[:strategy]),
|
|
22
|
+
seed: pc["seed"] || pc[:seed],
|
|
23
|
+
timing_path: nil,
|
|
24
|
+
constraints_path: nil,
|
|
25
|
+
timing_granularity: nil,
|
|
26
|
+
merge_coverage: false,
|
|
27
|
+
merge_output: nil,
|
|
28
|
+
merge_format: nil,
|
|
29
|
+
merge_failures: false,
|
|
30
|
+
merge_failures_output: nil,
|
|
31
|
+
merge_failures_format: nil,
|
|
32
|
+
merge_spec_quality: false,
|
|
33
|
+
merge_spec_quality_output: nil,
|
|
34
|
+
report_spec_quality: true,
|
|
35
|
+
worker_timeout_sec: env_worker_timeout_sec(cfg),
|
|
36
|
+
worker_idle_timeout_sec: nil
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def run_shards_plan_options_parse!(head, st)
|
|
41
|
+
OptionParser.new do |opts|
|
|
42
|
+
run_shards_plan_options_register!(opts, st)
|
|
43
|
+
end.parse!(head)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# rubocop:disable Metrics/AbcSize -- one argv block for run-shards
|
|
47
|
+
def run_shards_plan_options_register!(opts, st)
|
|
48
|
+
opts.banner = "usage: polyrun run-shards [--workers N] [--worker-timeout SEC] [--worker-idle-timeout SEC] [--strategy NAME] [--paths-file P] [--timing P] [--timing-granularity VAL] [--constraints P] [--seed S] [--merge-coverage] [--merge-output P] [--merge-format LIST] [--merge-failures] [--merge-failures-output P] [--merge-failures-format jsonl|json] [--merge-spec-quality] [--merge-spec-quality-output P] [--no-report-spec-quality] [--] <command> [args...]"
|
|
49
|
+
opts.on("--workers N", Integer) { |v| st[:workers] = v }
|
|
50
|
+
opts.on("--worker-timeout SEC", Float, "Max seconds per worker since spawn (also POLYRUN_WORKER_TIMEOUT_SEC); kills stuck workers (exit 124)") { |v| st[:worker_timeout_sec] = v }
|
|
51
|
+
opts.on("--worker-idle-timeout SEC", Float, "Max seconds since last worker progress ping (POLYRUN_WORKER_PING_FILE); enable pings in test setup; exit 125") { |v| st[:worker_idle_timeout_sec] = v }
|
|
52
|
+
opts.on("--strategy NAME", String) do |v|
|
|
53
|
+
st[:strategy] = v
|
|
54
|
+
st[:strategy_explicit] = true
|
|
55
|
+
end
|
|
56
|
+
opts.on("--seed VAL") { |v| st[:seed] = v }
|
|
57
|
+
opts.on("--paths-file PATH", String) { |v| st[:paths_file] = v }
|
|
58
|
+
opts.on("--constraints PATH", String) { |v| st[:constraints_path] = v }
|
|
59
|
+
opts.on("--timing PATH", "merged polyrun_timing.json; implies cost_binpack unless hrw/cost") { |v| st[:timing_path] = v }
|
|
60
|
+
opts.on("--timing-granularity VAL", "file (default) or example (experimental)") { |v| st[:timing_granularity] = v }
|
|
61
|
+
opts.on("--merge-coverage", "After success, merge coverage/polyrun-fragment-*.json (Polyrun coverage must be enabled)") { st[:merge_coverage] = true }
|
|
62
|
+
opts.on("--merge-output PATH", String) { |v| st[:merge_output] = v }
|
|
63
|
+
opts.on("--merge-format LIST", String) { |v| st[:merge_format] = v }
|
|
64
|
+
opts.on("--merge-failures", "After all workers exit, merge failure fragments from tmp/polyrun_failures (requires failure fragments in test setup)") { st[:merge_failures] = true }
|
|
65
|
+
opts.on("--merge-failures-output PATH", String) { |v| st[:merge_failures_output] = v }
|
|
66
|
+
opts.on("--merge-failures-format VAL", "jsonl (default), json, csv, or markdown") { |v| st[:merge_failures_format] = v }
|
|
67
|
+
opts.on("--merge-spec-quality", "After workers exit, merge spec-quality fragments from coverage (enable spec-quality collection in test setup)") { st[:merge_spec_quality] = true }
|
|
68
|
+
opts.on("--merge-spec-quality-output PATH", String) { |v| st[:merge_spec_quality_output] = v }
|
|
69
|
+
opts.on("--no-report-spec-quality", "Skip printing spec-quality report after merge") { st[:report_spec_quality] = false }
|
|
70
|
+
end
|
|
71
|
+
# rubocop:enable Metrics/AbcSize
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
require_relative "run_shards_plan_options"
|
|
2
|
+
require_relative "run_shards_plan_boot_phases"
|
|
3
|
+
|
|
4
|
+
module Polyrun
|
|
5
|
+
class CLI
|
|
6
|
+
# Parses argv, loads config, builds {Partition::Plan} for run-shards.
|
|
7
|
+
module RunShardsPlanning
|
|
8
|
+
include RunShardsPlanOptions
|
|
9
|
+
include RunShardsPlanBootPhases
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
# @return [Array(Integer, Hash, nil)] [exit_code, nil] on failure, or [nil, ctx] on success
|
|
14
|
+
def run_shards_build_plan(argv, config_path)
|
|
15
|
+
boot = run_shards_plan_boot(argv, config_path)
|
|
16
|
+
return boot if boot.size == 2
|
|
17
|
+
|
|
18
|
+
run_t0, head, cmd, cfg, pc = boot
|
|
19
|
+
phase = run_shards_plan_phase_a(head, cmd, pc, cfg)
|
|
20
|
+
return [phase[1], nil] if phase[0] == :fail
|
|
21
|
+
|
|
22
|
+
_tag, o, cmd = phase
|
|
23
|
+
run_shards_plan_phase_b(o, cmd, cfg, pc, run_t0, config_path)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def run_shards_default_timing_path(pc, timing_path, _strategy = nil)
|
|
27
|
+
return timing_path if timing_path
|
|
28
|
+
|
|
29
|
+
pc["timing_file"] || pc[:timing_file]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def run_shards_validate_workers!(o)
|
|
33
|
+
w = o[:workers]
|
|
34
|
+
if w < 1
|
|
35
|
+
Polyrun::Log.warn "polyrun run-shards: --workers must be >= 1"
|
|
36
|
+
return 2
|
|
37
|
+
end
|
|
38
|
+
if w > Polyrun::Config::MAX_PARALLEL_WORKERS
|
|
39
|
+
Polyrun::Log.warn "polyrun run-shards: capping --workers / POLYRUN_WORKERS from #{w} to #{Polyrun::Config::MAX_PARALLEL_WORKERS}"
|
|
40
|
+
o[:workers] = Polyrun::Config::MAX_PARALLEL_WORKERS
|
|
41
|
+
end
|
|
42
|
+
nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def run_shards_validate_cmd(cmd)
|
|
46
|
+
if cmd.empty?
|
|
47
|
+
Polyrun::Log.warn "polyrun run-shards: empty command after --"
|
|
48
|
+
return 2
|
|
49
|
+
end
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def run_shards_resolve_items(paths_file, partition)
|
|
54
|
+
resolved = Polyrun::Partition::Paths.resolve_run_shard_items(paths_file: paths_file, partition: partition)
|
|
55
|
+
if resolved[:error]
|
|
56
|
+
Polyrun::Log.warn "polyrun run-shards: #{resolved[:error]}"
|
|
57
|
+
return [nil, nil, 2]
|
|
58
|
+
end
|
|
59
|
+
items = resolved[:items]
|
|
60
|
+
paths_source = resolved[:source]
|
|
61
|
+
Polyrun::Log.warn "polyrun run-shards: #{items.size} path(s) from #{paths_source}"
|
|
62
|
+
|
|
63
|
+
if items.empty?
|
|
64
|
+
Polyrun::Log.warn "polyrun run-shards: no paths (empty paths file or list)"
|
|
65
|
+
return [nil, nil, 2]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
[items, paths_source, nil]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def run_shards_validate_suite_vs_command!(items, cmd)
|
|
72
|
+
msg = Polyrun::Partition::Suite.command_mismatch_message(items, cmd)
|
|
73
|
+
return nil unless msg
|
|
74
|
+
|
|
75
|
+
Polyrun::Log.warn "polyrun run-shards: #{msg}"
|
|
76
|
+
2
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def run_shards_resolve_costs(timing_path, strategy, timing_granularity, strategy_explicit: false)
|
|
80
|
+
partition_resolve_costs_and_strategy(
|
|
81
|
+
timing_path,
|
|
82
|
+
strategy,
|
|
83
|
+
timing_granularity,
|
|
84
|
+
strategy_explicit: strategy_explicit,
|
|
85
|
+
log_prefix: "polyrun run-shards"
|
|
86
|
+
)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def run_shards_make_plan(items, workers, strategy, seed, costs, constraints, timing_granularity, stable_assignment = nil, shard_weights: nil)
|
|
90
|
+
Polyrun::Debug.time("Partition::Plan.new (partition #{items.size} paths → #{workers} shards)") do
|
|
91
|
+
Polyrun::Partition::Plan.new(
|
|
92
|
+
items: items,
|
|
93
|
+
total_shards: workers,
|
|
94
|
+
strategy: strategy,
|
|
95
|
+
seed: seed,
|
|
96
|
+
costs: costs,
|
|
97
|
+
constraints: constraints,
|
|
98
|
+
root: Dir.pwd,
|
|
99
|
+
timing_granularity: timing_granularity,
|
|
100
|
+
stable_assignment: stable_assignment,
|
|
101
|
+
shard_weights: shard_weights
|
|
102
|
+
)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def run_shards_debug_shard_sizes(plan, workers)
|
|
107
|
+
return unless Polyrun::Debug.enabled?
|
|
108
|
+
|
|
109
|
+
workers.times do |s|
|
|
110
|
+
n = plan.shard(s).size
|
|
111
|
+
Polyrun::Debug.log("run-shards: shard #{s} → #{n} spec file(s)")
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def run_shards_warn_parallel_banner(item_count, workers, strategy)
|
|
116
|
+
Polyrun::Log.warn <<~MSG
|
|
117
|
+
polyrun run-shards: #{item_count} path(s) -> #{workers} parallel worker processes (not Ruby threads); strategy=#{strategy}
|
|
118
|
+
(plain `bundle exec rspec` is one process; this command fans out.)
|
|
119
|
+
MSG
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
require "shellwords"
|
|
2
|
+
require "rbconfig"
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
require_relative "run_shards_planning"
|
|
6
|
+
require_relative "run_shards_worker_interrupt"
|
|
7
|
+
require_relative "run_shards_parallel_children"
|
|
8
|
+
|
|
9
|
+
module Polyrun
|
|
10
|
+
class CLI
|
|
11
|
+
# Partition + spawn workers for `polyrun run-shards` (keeps {RunShardsCommand} file small).
|
|
12
|
+
module RunShardsRun
|
|
13
|
+
include RunShardsPlanning
|
|
14
|
+
include RunShardsWorkerInterrupt
|
|
15
|
+
include RunShardsParallelChildren
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def run_shards_run!(argv, config_path)
|
|
20
|
+
code, ctx = run_shards_build_plan(argv, config_path)
|
|
21
|
+
return code if code
|
|
22
|
+
|
|
23
|
+
run_shards_workers_and_merge(ctx)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity -- orchestration: hooks, merge, worker failures
|
|
27
|
+
def run_shards_workers_and_merge(ctx)
|
|
28
|
+
hook_cfg = Polyrun::Hooks.from_config(ctx[:cfg])
|
|
29
|
+
suite_started = false
|
|
30
|
+
exit_code = 1
|
|
31
|
+
merged_failures_path = nil
|
|
32
|
+
merge_failures_errored = false
|
|
33
|
+
merge_spec_quality_errored = false
|
|
34
|
+
spec_quality_strict_failed = false
|
|
35
|
+
|
|
36
|
+
begin
|
|
37
|
+
env_suite = ENV.to_h.merge(
|
|
38
|
+
"POLYRUN_HOOK_ORCHESTRATOR" => "1",
|
|
39
|
+
"POLYRUN_SHARD_TOTAL" => ctx[:workers].to_s
|
|
40
|
+
)
|
|
41
|
+
code = hook_cfg.run_phase_if_enabled(:before_suite, env_suite)
|
|
42
|
+
return code if code != 0
|
|
43
|
+
|
|
44
|
+
suite_started = true
|
|
45
|
+
|
|
46
|
+
pids, spawn_err = run_shards_spawn_workers(ctx, hook_cfg)
|
|
47
|
+
if spawn_err
|
|
48
|
+
exit_code = spawn_err
|
|
49
|
+
return spawn_err
|
|
50
|
+
end
|
|
51
|
+
if pids.empty?
|
|
52
|
+
exit_code = 1
|
|
53
|
+
return 1
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
run_shards_warn_interleaved(ctx[:parallel], pids.size)
|
|
57
|
+
|
|
58
|
+
shard_results, wait_hook_err = run_shards_wait_all_children(pids, hook_cfg, ctx)
|
|
59
|
+
failed = shard_results.reject { |r| r[:success] }.map { |r| r[:shard] }
|
|
60
|
+
|
|
61
|
+
Polyrun::Debug.log(format(
|
|
62
|
+
"run-shards: workers wall time since start: %.3fs",
|
|
63
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC) - ctx[:run_t0]
|
|
64
|
+
))
|
|
65
|
+
|
|
66
|
+
if ctx[:parallel]
|
|
67
|
+
Polyrun::Log.warn "polyrun run-shards: finished #{pids.size} worker(s)" + (failed.any? ? " (some failed)" : " (exit 0)")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
if ctx[:merge_spec_quality]
|
|
71
|
+
begin
|
|
72
|
+
merged_sq_path = merge_spec_quality_after_shards(ctx)
|
|
73
|
+
if merged_sq_path && ctx[:report_spec_quality]
|
|
74
|
+
cfg = load_spec_quality_config(nil)
|
|
75
|
+
merged = JSON.parse(File.read(merged_sq_path))
|
|
76
|
+
spec_quality_strict_failed = cfg["strict"] && Polyrun::SpecQuality::Report.gate_violations(merged, cfg).any?
|
|
77
|
+
end
|
|
78
|
+
rescue Polyrun::Error, JSON::ParserError => e
|
|
79
|
+
Polyrun::Log.warn e.message.to_s
|
|
80
|
+
merge_spec_quality_errored = true
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
if ctx[:merge_failures]
|
|
85
|
+
begin
|
|
86
|
+
merged_failures_path = merge_failures_after_shards(ctx)
|
|
87
|
+
rescue Polyrun::Error => e
|
|
88
|
+
Polyrun::Log.warn e.message.to_s
|
|
89
|
+
merge_failures_errored = true
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
if failed.any?
|
|
94
|
+
run_shards_log_failed_reruns(
|
|
95
|
+
failed, shard_results, ctx[:plan], ctx[:parallel], ctx[:workers], ctx[:cmd],
|
|
96
|
+
merge_failures: ctx[:merge_failures]
|
|
97
|
+
)
|
|
98
|
+
exit_code = 1
|
|
99
|
+
return exit_code
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
exit_code = run_shards_merge_or_hint_coverage(ctx)
|
|
103
|
+
exit_code = 1 if wait_hook_err != 0 && exit_code == 0
|
|
104
|
+
exit_code = 1 if merge_spec_quality_errored && exit_code == 0
|
|
105
|
+
exit_code = 1 if spec_quality_strict_failed && exit_code == 0
|
|
106
|
+
exit_code
|
|
107
|
+
ensure
|
|
108
|
+
if suite_started
|
|
109
|
+
env_after = ENV.to_h.merge(
|
|
110
|
+
"POLYRUN_HOOK_ORCHESTRATOR" => "1",
|
|
111
|
+
"POLYRUN_SHARD_TOTAL" => ctx[:workers].to_s,
|
|
112
|
+
"POLYRUN_SUITE_EXIT_STATUS" => exit_code.to_s,
|
|
113
|
+
"POLYRUN_MERGED_FAILURES_PATH" => merged_failures_path.to_s
|
|
114
|
+
)
|
|
115
|
+
begin
|
|
116
|
+
hook_cfg.run_phase_if_enabled(:after_suite, env_after)
|
|
117
|
+
rescue Interrupt
|
|
118
|
+
Polyrun::Log.warn "polyrun run-shards: after_suite hook interrupted; workers are stopped or were not started"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
124
|
+
|
|
125
|
+
def run_shards_warn_interleaved(parallel, pid_count)
|
|
126
|
+
return unless parallel && pid_count > 1
|
|
127
|
+
return if Polyrun::WorkerOutput.routing_enabled?
|
|
128
|
+
|
|
129
|
+
Polyrun::Log.warn "polyrun run-shards: #{pid_count} children running; RSpec output below may be interleaved."
|
|
130
|
+
Polyrun::Log.warn "polyrun run-shards: RSpec summary counts apply to individual shards."
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def run_shards_merge_or_hint_coverage(ctx)
|
|
134
|
+
if ctx[:merge_coverage]
|
|
135
|
+
mo = ctx[:merge_output] || "coverage/merged.json"
|
|
136
|
+
mf = ctx[:merge_format] || ENV["POLYRUN_MERGE_FORMATS"] || Polyrun::Coverage::Reporting::DEFAULT_MERGE_FORMAT_LIST
|
|
137
|
+
Polyrun::Debug.log("run-shards: starting post-worker merge_coverage_after_shards → #{mo}")
|
|
138
|
+
return merge_coverage_after_shards(output: mo, format_list: mf, config_path: ctx[:config_path])
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
if ctx[:parallel]
|
|
142
|
+
Polyrun::Log.warn <<~MSG
|
|
143
|
+
polyrun run-shards: coverage — each worker writes coverage/polyrun-fragment-worker<N>.json when Polyrun coverage is enabled (POLYRUN_SHARD_INDEX per process).
|
|
144
|
+
polyrun run-shards: next step — merge with: polyrun merge-coverage -i 'coverage/polyrun-fragment-*.json' -o coverage/merged.json --format json,cobertura,console
|
|
145
|
+
MSG
|
|
146
|
+
end
|
|
147
|
+
0
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def run_shards_log_failed_reruns(failed, shard_results, plan, parallel, workers, cmd, merge_failures: false)
|
|
151
|
+
exit_by_shard = shard_results.each_with_object({}) { |r, h| h[r[:shard]] = r[:exitstatus] }
|
|
152
|
+
failed_detail = failed.sort.map { |s| "#{s} (exit #{exit_by_shard[s]})" }.join(", ")
|
|
153
|
+
Polyrun::Log.warn "polyrun run-shards: failed shard(s): #{failed_detail}"
|
|
154
|
+
if parallel
|
|
155
|
+
Polyrun::Log.warn "polyrun run-shards: search this log for the failed shard's output, or re-run one shard at a time (below) for a clean RSpec report."
|
|
156
|
+
end
|
|
157
|
+
failed.sort.each do |s|
|
|
158
|
+
paths = plan.shard(s)
|
|
159
|
+
next if paths.empty?
|
|
160
|
+
|
|
161
|
+
rerun = "export POLYRUN_SHARD_INDEX=#{s} POLYRUN_SHARD_TOTAL=#{workers}; "
|
|
162
|
+
rerun << Shellwords.join(cmd + paths)
|
|
163
|
+
Polyrun::Log.warn "polyrun run-shards: shard #{s} re-run (same spec list, no interleave): #{rerun}"
|
|
164
|
+
end
|
|
165
|
+
unless merge_failures
|
|
166
|
+
Polyrun::Log.warn "polyrun run-shards: for one combined failure report, add --merge-failures (requires failure fragments enabled in your test setup)"
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require_relative "../worker_output"
|
|
2
|
+
|
|
3
|
+
module Polyrun
|
|
4
|
+
class CLI
|
|
5
|
+
# SIGINT/SIGTERM handling and non-blocking reap for parallel worker PIDs (used by run-shards / ci-shard fan-out).
|
|
6
|
+
module RunShardsWorkerInterrupt
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
def run_shards_with_interrupt_handlers
|
|
10
|
+
previous = {}
|
|
11
|
+
handlers = {"INT" => ->(_) { raise Interrupt }, "TERM" => ->(_) { raise SignalException, "SIGTERM" }}
|
|
12
|
+
handlers.each do |signal, handler|
|
|
13
|
+
original = Signal.trap(signal, handler)
|
|
14
|
+
if original == "DEFAULT"
|
|
15
|
+
previous[signal] = original
|
|
16
|
+
else
|
|
17
|
+
Signal.trap(signal, original)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
yield
|
|
21
|
+
ensure
|
|
22
|
+
previous.each { |signal, handler| Signal.trap(signal, handler) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def run_shards_log_interrupt_workers(pids, _ctx)
|
|
26
|
+
parts = pids.map { |h| "shard=#{h[:shard]} pid=#{h[:pid]}" }
|
|
27
|
+
Polyrun::Log.orchestration_warn "polyrun run-shards: SIGINT/SIGTERM while waiting on workers — stopping: #{parts.join(", ")}"
|
|
28
|
+
if Polyrun::WorkerOutput.routing_enabled?
|
|
29
|
+
Polyrun::Log.warn "polyrun run-shards: per-shard worker logs under #{Polyrun::WorkerOutput.worker_log_directory_label}"
|
|
30
|
+
else
|
|
31
|
+
Polyrun::Log.warn "polyrun run-shards: search this log for each shard's started … pid= line and RSpec output; repeat SIGINT during cleanup escalates to SIGKILL"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Best-effort worker teardown then exit. Does not return.
|
|
36
|
+
def run_shards_shutdown_on_signal!(pids, code)
|
|
37
|
+
run_shards_log_interrupt_workers(pids, nil)
|
|
38
|
+
run_shards_terminate_children!(pids)
|
|
39
|
+
exit(code)
|
|
40
|
+
rescue Interrupt
|
|
41
|
+
run_shards_signal_workers_kill(pids)
|
|
42
|
+
run_shards_reap_worker_pids_interruptible(pids.map { |h| h[:pid] })
|
|
43
|
+
Polyrun::WorkerOutput.shutdown_all!
|
|
44
|
+
exit(code)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Signal workers first so pipe readers see EOF; join forwarders only after children exit.
|
|
48
|
+
def run_shards_terminate_children!(pids)
|
|
49
|
+
run_shards_signal_workers_term(pids)
|
|
50
|
+
run_shards_reap_worker_pids_interruptible(pids.map { |h| h[:pid] })
|
|
51
|
+
Polyrun::WorkerOutput.shutdown_all!
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def run_shards_signal_workers_term(pids)
|
|
55
|
+
pids.each { |h| run_shards_kill_process_group!(:TERM, h[:pid]) }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def run_shards_signal_workers_kill(pids)
|
|
59
|
+
pids.each { |h| run_shards_kill_process_group!(:KILL, h[:pid]) }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Negative PID signals the process group (workers spawn with +pgroup: true+).
|
|
63
|
+
def run_shards_kill_process_group!(signal, pid)
|
|
64
|
+
Process.kill(signal, -Integer(pid))
|
|
65
|
+
rescue Errno::ESRCH, Errno::EPERM
|
|
66
|
+
begin
|
|
67
|
+
Process.kill(signal, Integer(pid))
|
|
68
|
+
rescue Errno::ESRCH, Errno::EPERM
|
|
69
|
+
nil
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Reap child PIDs without blocking uninterruptibly on one stuck zombie (avoids noisy stacks on repeat Ctrl+C).
|
|
74
|
+
def run_shards_reap_worker_pids_interruptible(pids)
|
|
75
|
+
pending = pids.compact.uniq
|
|
76
|
+
force_note = false
|
|
77
|
+
until pending.empty?
|
|
78
|
+
pending.reject! do |pid|
|
|
79
|
+
w = Process.wait(pid, Process::WNOHANG)
|
|
80
|
+
next true if w == pid
|
|
81
|
+
|
|
82
|
+
false
|
|
83
|
+
rescue Errno::ECHILD
|
|
84
|
+
true
|
|
85
|
+
end
|
|
86
|
+
break if pending.empty?
|
|
87
|
+
|
|
88
|
+
begin
|
|
89
|
+
sleep(0.05)
|
|
90
|
+
rescue Interrupt
|
|
91
|
+
unless force_note
|
|
92
|
+
force_note = true
|
|
93
|
+
Polyrun::Log.orchestration_warn "polyrun run-shards: repeated SIGINT during worker cleanup — SIGKILL to #{pending.size} process(es)"
|
|
94
|
+
end
|
|
95
|
+
pending.each { |pid| run_shards_kill_process_group!(:KILL, pid) }
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|