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,212 @@
|
|
|
1
|
+
# rubocop:disable Polyrun/FileLength -- per-example recorder API
|
|
2
|
+
require "json"
|
|
3
|
+
require "fileutils"
|
|
4
|
+
|
|
5
|
+
require_relative "coverage/example_diff"
|
|
6
|
+
require_relative "partition/timing_keys"
|
|
7
|
+
require_relative "spec_quality/config"
|
|
8
|
+
require_relative "spec_quality/profile"
|
|
9
|
+
require_relative "spec_quality/fragment"
|
|
10
|
+
require_relative "spec_quality/sql_counter"
|
|
11
|
+
require_relative "spec_quality/merge"
|
|
12
|
+
require_relative "spec_quality/plan_loader"
|
|
13
|
+
require_relative "spec_quality/report"
|
|
14
|
+
require_relative "spec_quality/rspec_hook"
|
|
15
|
+
require_relative "spec_quality/minitest_hook"
|
|
16
|
+
|
|
17
|
+
module Polyrun
|
|
18
|
+
# Per-example spec quality: coverage line deltas, resource use, optional SQL counts.
|
|
19
|
+
# Opt-in with +POLYRUN_SPEC_QUALITY=1+ or +Polyrun::SpecQuality.start!+.
|
|
20
|
+
module SpecQuality
|
|
21
|
+
class << self
|
|
22
|
+
def start!(root: Dir.pwd, config_path: nil, output_path: nil, **overrides)
|
|
23
|
+
return if Config.disabled?
|
|
24
|
+
|
|
25
|
+
@config = Config.load(root: root, config_path: config_path, **overrides)
|
|
26
|
+
@output_path = output_path || Fragment.default_fragment_path
|
|
27
|
+
@pause_depth = 0
|
|
28
|
+
@current = nil
|
|
29
|
+
@rng = Random.new(Process.pid ^ Time.now.to_i)
|
|
30
|
+
|
|
31
|
+
Fragment.truncate_fragment!(@output_path) unless fragment_append_mode?
|
|
32
|
+
SqlCounter.install! if @config["sql_counter"]
|
|
33
|
+
self
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def started?
|
|
37
|
+
instance_variable_defined?(:@config) && @config
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def enabled?(root: Dir.pwd)
|
|
41
|
+
Config.enabled?(ENV, root: root) && !Config.disabled?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
attr_reader :config
|
|
45
|
+
|
|
46
|
+
attr_reader :output_path
|
|
47
|
+
|
|
48
|
+
def recording?
|
|
49
|
+
started? && @current && @pause_depth.zero?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def start_example!(location:, wall_start: nil)
|
|
53
|
+
return unless started?
|
|
54
|
+
return if paused?
|
|
55
|
+
return if Config.ignored_example?(location, @config["ignore_examples"])
|
|
56
|
+
return unless sample_example?
|
|
57
|
+
|
|
58
|
+
@current = {
|
|
59
|
+
location: normalize_location(location),
|
|
60
|
+
wall_start: wall_start || Process.clock_gettime(Process::CLOCK_MONOTONIC),
|
|
61
|
+
coverage_before: Coverage::ExampleDiff.peek_blob(
|
|
62
|
+
root: @config["root"],
|
|
63
|
+
track_under: @config["track_under"],
|
|
64
|
+
ignore_paths: @config["ignore_paths"]
|
|
65
|
+
),
|
|
66
|
+
profile_before: Profile.snapshot(dimensions: @config["profile"]),
|
|
67
|
+
sql_count: 0,
|
|
68
|
+
sql_fingerprints: Hash.new(0),
|
|
69
|
+
factory_counts: {}
|
|
70
|
+
}
|
|
71
|
+
Polyrun::Data::FactoryCounts.reset_example! if defined?(Polyrun::Data::FactoryCounts)
|
|
72
|
+
nil
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def finish_example!(location: nil, pending: false)
|
|
76
|
+
return unless started?
|
|
77
|
+
cur = @current
|
|
78
|
+
@current = nil
|
|
79
|
+
return if cur.nil? || paused?
|
|
80
|
+
return if pending
|
|
81
|
+
|
|
82
|
+
loc = location || cur[:location]
|
|
83
|
+
return if loc.nil? || loc.to_s.empty?
|
|
84
|
+
|
|
85
|
+
delta = coverage_delta_for_example(cur)
|
|
86
|
+
|
|
87
|
+
profile_after = Profile.snapshot(dimensions: @config["profile"])
|
|
88
|
+
profile_delta = Profile.diff(cur[:profile_before], profile_after)
|
|
89
|
+
wall = Process.clock_gettime(Process::CLOCK_MONOTONIC) - cur[:wall_start]
|
|
90
|
+
profile_delta["wall"] = wall
|
|
91
|
+
|
|
92
|
+
factory_counts =
|
|
93
|
+
if defined?(Polyrun::Data::FactoryCounts)
|
|
94
|
+
Polyrun::Data::FactoryCounts.example_counts
|
|
95
|
+
else
|
|
96
|
+
{}
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
row = build_row(cur, loc, delta, profile_delta, factory_counts)
|
|
100
|
+
Fragment.append_row!(@output_path, row)
|
|
101
|
+
row
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def pause
|
|
105
|
+
@pause_depth += 1
|
|
106
|
+
if block_given?
|
|
107
|
+
begin
|
|
108
|
+
yield
|
|
109
|
+
ensure
|
|
110
|
+
resume
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def resume
|
|
116
|
+
@pause_depth -= 1 if @pause_depth.positive?
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def paused?
|
|
120
|
+
@pause_depth.positive?
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def record_sql!(sql)
|
|
124
|
+
return unless recording?
|
|
125
|
+
|
|
126
|
+
@current[:sql_count] += 1
|
|
127
|
+
fp = normalize_sql(sql)
|
|
128
|
+
@current[:sql_fingerprints][fp] += 1
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def spec_quality_requested_for_quick?(root = Dir.pwd)
|
|
132
|
+
return false if Config.disabled?
|
|
133
|
+
return true if Config.enabled?(ENV, root: root)
|
|
134
|
+
|
|
135
|
+
path = File.join(File.expand_path(root), Config::DEFAULT_CONFIG_RELATIVE)
|
|
136
|
+
return false unless File.file?(path)
|
|
137
|
+
|
|
138
|
+
%w[1 true yes].include?(ENV["POLYRUN_QUICK_SPEC_QUALITY"]&.to_s&.downcase)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
private
|
|
142
|
+
|
|
143
|
+
def fragment_append_mode?
|
|
144
|
+
truthy?(ENV["POLYRUN_SPEC_QUALITY_FRAGMENT_APPEND"])
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def sample_example?
|
|
148
|
+
rate = @config["sample"].to_f
|
|
149
|
+
return true if rate >= 1.0
|
|
150
|
+
return false if rate <= 0.0
|
|
151
|
+
|
|
152
|
+
@rng.rand < rate
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def normalize_location(location)
|
|
156
|
+
s = location.to_s.strip
|
|
157
|
+
return s if s.empty?
|
|
158
|
+
|
|
159
|
+
root = @config["root"]
|
|
160
|
+
if (m = s.match(/\A(.+):(\d+)\z/)) && m[2].match?(/\A\d+\z/)
|
|
161
|
+
fp = Polyrun::Partition::TimingKeys.canonical_file_path(File.expand_path(m[1], root))
|
|
162
|
+
return "#{fp}:#{m[2]}"
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
Polyrun::Partition::TimingKeys.canonical_file_path(File.expand_path(s, root))
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def coverage_delta_for_example(cur)
|
|
169
|
+
after_source = Coverage::ExampleDiff.coverage_active? ? ::Coverage.peek_result : {}
|
|
170
|
+
Coverage::ExampleDiff.diff(
|
|
171
|
+
cur[:coverage_before],
|
|
172
|
+
after_source,
|
|
173
|
+
root: @config["root"],
|
|
174
|
+
track_under: @config["track_under"],
|
|
175
|
+
ignore_paths: @config["ignore_paths"]
|
|
176
|
+
)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def build_row(cur, location, delta, profile_delta, factory_counts)
|
|
180
|
+
profile = Profile.slice_profile(profile_delta, @config["profile"])
|
|
181
|
+
repeated_sql = cur[:sql_fingerprints].select { |_sql, n| n >= min_query_count }.transform_keys(&:to_s)
|
|
182
|
+
|
|
183
|
+
{
|
|
184
|
+
"example" => location.to_s,
|
|
185
|
+
"unique_lines" => delta[:unique_lines],
|
|
186
|
+
"line_churn" => delta[:line_churn],
|
|
187
|
+
"max_line_churn" => delta[:max_line_churn],
|
|
188
|
+
"lines" => delta[:lines],
|
|
189
|
+
"profile" => profile,
|
|
190
|
+
"sql_count" => cur[:sql_count],
|
|
191
|
+
"repeated_sql" => repeated_sql,
|
|
192
|
+
"factory_counts" => factory_counts.transform_keys(&:to_s),
|
|
193
|
+
"polyrun_shard_index" => ENV["POLYRUN_SHARD_INDEX"],
|
|
194
|
+
"polyrun_shard_total" => ENV["POLYRUN_SHARD_TOTAL"]
|
|
195
|
+
}.compact
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def min_query_count
|
|
199
|
+
@config["min_query_count"].to_i
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def normalize_sql(sql)
|
|
203
|
+
sql.to_s.gsub(/\s+/, " ").strip[0, 500]
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def truthy?(value)
|
|
207
|
+
Config.send(:truthy?, value)
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
# rubocop:enable Polyrun/FileLength
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require_relative "../polyrun"
|
|
2
|
+
|
|
3
|
+
module Polyrun
|
|
4
|
+
# Optional Sus-oriented wiring (require +polyrun/sus_support+ explicitly).
|
|
5
|
+
#
|
|
6
|
+
# Does not load the +sus+ gem. Call installers from +config/sus.rb+ after Sus is available
|
|
7
|
+
# when a hook needs +Sus::Config+.
|
|
8
|
+
module SusSupport
|
|
9
|
+
module WorkerPingConfigHook
|
|
10
|
+
def before_tests(assertions, output: self.output)
|
|
11
|
+
Polyrun::WorkerPing.ping!(location: "sus:before_tests")
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def after_tests(assertions, output: self.output)
|
|
16
|
+
super
|
|
17
|
+
Polyrun::WorkerPing.ping!(location: "sus:after_tests")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
module_function
|
|
22
|
+
|
|
23
|
+
# Runs {Data::ParallelProvisioning.run_suite_hooks!} (serial vs shard worker hooks).
|
|
24
|
+
def install_parallel_provisioning!
|
|
25
|
+
Polyrun::Data::ParallelProvisioning.run_suite_hooks!
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Start {Coverage::Collector} when Polyrun or Covered coverage env is on.
|
|
29
|
+
# Prefer this for shard fragment merge. If Covered::Sus is already included on +Sus::Config+,
|
|
30
|
+
# skip starting the collector so +Coverage.start+ is not contested in one process.
|
|
31
|
+
def install_coverage!(root: Dir.pwd, **kwargs)
|
|
32
|
+
require_relative "coverage/collector"
|
|
33
|
+
return unless Polyrun::Coverage::Collector.coverage_requested_for_quick?(root)
|
|
34
|
+
|
|
35
|
+
if defined?(::Covered::Sus) && defined?(::Sus::Config) && ::Sus::Config.ancestors.include?(::Covered::Sus)
|
|
36
|
+
Polyrun::Log.warn "polyrun sus_support: install_coverage! skipped (Covered::Sus already on Sus::Config; use one coverage collector per process)"
|
|
37
|
+
return
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
Polyrun::Coverage::Collector.start!(root: root, **kwargs)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Ping at Sus +before_tests+ / +after_tests+ when +Sus::Config+ is defined.
|
|
44
|
+
def install_worker_ping!
|
|
45
|
+
require_relative "worker_ping"
|
|
46
|
+
unless defined?(::Sus::Config)
|
|
47
|
+
Polyrun::Log.warn "polyrun sus_support: install_worker_ping! skipped (load Sus before calling)"
|
|
48
|
+
return
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
::Sus::Config.prepend(WorkerPingConfigHook)
|
|
52
|
+
Polyrun::WorkerPing.ensure_interval_ping_thread!
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Polyrun in this project
|
|
2
|
+
|
|
3
|
+
This repo uses [Polyrun](https://github.com/amkisko/polyrun.rb) for parallel RSpec, merged coverage, and optional CI report formats.
|
|
4
|
+
|
|
5
|
+
## Setup profile
|
|
6
|
+
|
|
7
|
+
Fill in and keep updated: dimensions are summarized in Polyrun’s [SETUP_PROFILE checklist](https://github.com/amkisko/polyrun.rb/blob/main/docs/SETUP_PROFILE.md) (project type, DB, prepare, CI model).
|
|
8
|
+
|
|
9
|
+
## Canonical commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bundle exec polyrun -c polyrun.yml build-paths
|
|
13
|
+
bundle exec polyrun -c polyrun.yml parallel-rspec --workers 5
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Adjust `--workers` or use `bin/rspec_parallel` if your repo provides a wrapper.
|
|
17
|
+
|
|
18
|
+
## CI model (choose one and match your workflows)
|
|
19
|
+
|
|
20
|
+
### Model A — single CI job, N worker processes on one runner
|
|
21
|
+
|
|
22
|
+
- Run `polyrun -c polyrun.yml parallel-rspec --workers N` (or `polyrun start`).
|
|
23
|
+
- Merge coverage in the same job (or a follow-up step) from `coverage/polyrun-fragment-*.json`.
|
|
24
|
+
|
|
25
|
+
### Model B — matrix: one shard per job
|
|
26
|
+
|
|
27
|
+
- Matrix sets `POLYRUN_SHARD_INDEX` and `POLYRUN_SHARD_TOTAL` explicitly (many runners do not set `CI_NODE_*` by default).
|
|
28
|
+
- Each job runs `polyrun ci-shard-run -- …` (e.g. `-- bundle exec rspec` or `ci-shard-rspec`), or `build-paths` + `plan` + your runner manually. Legacy: `bin/polyrun-rspec` or `bin/rspec_ci_shard` patterns.
|
|
29
|
+
- Upload `coverage/polyrun-fragment-<shard>.json` per job; a `merge-coverage` job downloads all fragments and merges.
|
|
30
|
+
|
|
31
|
+
Do not combine Model A and Model B in one workflow without a documented reason (nested parallelism and duplicate merges).
|
|
32
|
+
|
|
33
|
+
## Configuration contract
|
|
34
|
+
|
|
35
|
+
- `polyrun.yml` — partition, optional `prepare`, optional `databases`. This file is the source of truth for shard indices and paths.
|
|
36
|
+
- Adapters — thin scripts (`bin/rspec_parallel`, `bin/polyrun-rspec`, `database.yml` ERB, prepare scripts) must match `polyrun.yml`.
|
|
37
|
+
|
|
38
|
+
## Coverage
|
|
39
|
+
|
|
40
|
+
- `spec/spec_helper.rb`: `require "polyrun"` and collector or Rails helper as appropriate.
|
|
41
|
+
- Fragments: `coverage/polyrun-fragment-<shard>.json` → `polyrun merge-coverage` → `polyrun report-coverage` / `report-junit` for CI.
|
|
42
|
+
|
|
43
|
+
## Spec quality (optional)
|
|
44
|
+
|
|
45
|
+
- `POLYRUN_SPEC_QUALITY=1` and `Polyrun::RSpecSupport.install_spec_quality!` in `spec_helper` (requires coverage enabled for line deltas).
|
|
46
|
+
- `config/polyrun_spec_quality.yml` — thresholds and CI gates (`polyrun init --profile spec-quality`).
|
|
47
|
+
- Parallel: `run-shards --merge-spec-quality` → `coverage/polyrun-spec-quality.json` → `report-spec-quality`.
|
|
48
|
+
|
|
49
|
+
## Further reading
|
|
50
|
+
|
|
51
|
+
- Polyrun README: partition, prepare, databases, merge-coverage, `Polyrun::Env::Ci`
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Polyrun — partition contract for CI matrix (one job per POLYRUN_SHARD_INDEX).
|
|
2
|
+
# Each matrix row: set POLYRUN_SHARD_INDEX and POLYRUN_SHARD_TOTAL; run:
|
|
3
|
+
# bundle exec polyrun -c polyrun.yml ci-shard-run -- bundle exec rspec
|
|
4
|
+
# (or ci-shard-rspec; or e.g. ci-shard-run -- bundle exec polyrun quick).
|
|
5
|
+
# Equivalent to build-paths, plan --shard/--total, then run that command with this slice's paths.
|
|
6
|
+
# A separate CI job downloads coverage/polyrun-fragment-*.json (e.g. shard<S>-worker<W>.json per N×M process) and runs merge-coverage.
|
|
7
|
+
# For N×M (N matrix jobs × M processes per job): set shard_processes: M or POLYRUN_SHARD_PROCESSES,
|
|
8
|
+
# or pass --shard-processes M to ci-shard-run / ci-shard-rspec (local split is round-robin).
|
|
9
|
+
# See: docs/SETUP_PROFILE.md
|
|
10
|
+
|
|
11
|
+
partition:
|
|
12
|
+
paths_file: spec/spec_paths.txt
|
|
13
|
+
shard_total: 5
|
|
14
|
+
shard_index: 0
|
|
15
|
+
strategy: round_robin
|
|
16
|
+
paths_build:
|
|
17
|
+
all_glob: spec/**/*_spec.rb
|
|
18
|
+
stages: []
|
|
19
|
+
|
|
20
|
+
# Optional reporting (see docs/SPEC_QUALITY.md):
|
|
21
|
+
# reporting:
|
|
22
|
+
# merge_spec_quality: true
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Polyrun — minimal gem/library layout (no Rails prepare, no databases: block).
|
|
2
|
+
# Fill in paths_build.stages if you need regex or substring ordering for slow specs.
|
|
3
|
+
# Next: spec_helper — require "polyrun" + Polyrun::Coverage::Collector (or your collector config)
|
|
4
|
+
# See: docs/SETUP_PROFILE.md
|
|
5
|
+
|
|
6
|
+
partition:
|
|
7
|
+
paths_file: spec/spec_paths.txt
|
|
8
|
+
shard_total: 5
|
|
9
|
+
shard_index: 0
|
|
10
|
+
strategy: round_robin
|
|
11
|
+
paths_build:
|
|
12
|
+
all_glob: spec/**/*_spec.rb
|
|
13
|
+
stages: []
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Optional Polyrun hooks — copy to config/polyrun_hooks.rb and reference from polyrun.yml:
|
|
2
|
+
# hooks:
|
|
3
|
+
# ruby_file: config/polyrun_hooks.rb
|
|
4
|
+
#
|
|
5
|
+
# Worker-phase hooks run in each parallel test child (around bundle exec rspec).
|
|
6
|
+
|
|
7
|
+
before(:each) do |env|
|
|
8
|
+
next unless env["POLYRUN_HOOK_ORCHESTRATOR"] == "0"
|
|
9
|
+
next unless defined?(Polyrun::SpecQuality) && Polyrun::SpecQuality.enabled?
|
|
10
|
+
|
|
11
|
+
Polyrun::SpecQuality::RspecHook.ensure_started!
|
|
12
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Opt-in per-example spec quality (coverage deltas, resource use). See docs/SPEC_QUALITY.md.
|
|
2
|
+
track_under:
|
|
3
|
+
- lib
|
|
4
|
+
- app
|
|
5
|
+
min_line_churn: 50
|
|
6
|
+
min_query_count: 20
|
|
7
|
+
hot_line_example_overlap: 10
|
|
8
|
+
strict: false
|
|
9
|
+
sample: 1.0
|
|
10
|
+
ignore_examples: []
|
|
11
|
+
ignore_paths: []
|
|
12
|
+
ignore_query_patterns: []
|
|
13
|
+
profile:
|
|
14
|
+
- cpu
|
|
15
|
+
- mem
|
|
16
|
+
sql_counter: false
|
|
17
|
+
# CI gates (used with POLYRUN_SPEC_QUALITY_STRICT=1 or strict: true):
|
|
18
|
+
# minimum_unique_lines_per_example: 1
|
|
19
|
+
# max_zero_hit_examples: 0
|
|
20
|
+
# max_hot_line_overlap: 100
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Polyrun — Rails app with one-shot prepare before parallel workers.
|
|
2
|
+
# Adjust prepare.command to your repo (assets, Playwright, webapp build, etc.).
|
|
3
|
+
# Gate per-worker duplicate work in application code when POLYRUN_SHARD_TOTAL > 1.
|
|
4
|
+
# See: docs/SETUP_PROFILE.md
|
|
5
|
+
|
|
6
|
+
version: 1
|
|
7
|
+
|
|
8
|
+
partition:
|
|
9
|
+
paths_file: spec/spec_paths.txt
|
|
10
|
+
shard_total: 5
|
|
11
|
+
shard_index: 0
|
|
12
|
+
strategy: round_robin
|
|
13
|
+
paths_build:
|
|
14
|
+
all_glob: spec/**/*_spec.rb
|
|
15
|
+
stages: []
|
|
16
|
+
|
|
17
|
+
prepare:
|
|
18
|
+
recipe: shell
|
|
19
|
+
rails_root: .
|
|
20
|
+
command: bundle exec ruby bin/test_prepare.rb
|
|
21
|
+
|
|
22
|
+
start:
|
|
23
|
+
prepare: true
|
|
24
|
+
databases: true
|
|
25
|
+
|
|
26
|
+
# Optional suite hooks (uncomment and set commands):
|
|
27
|
+
# hooks:
|
|
28
|
+
# before_suite: bundle exec ruby script/polyrun_before_suite.rb
|
|
29
|
+
# after_suite: bundle exec ruby script/polyrun_after_suite.rb
|
|
30
|
+
hooks: {}
|
|
31
|
+
|
|
32
|
+
# Optional reporting (see docs/SPEC_QUALITY.md):
|
|
33
|
+
# reporting:
|
|
34
|
+
# merge_failures: true
|
|
35
|
+
# merge_spec_quality: true
|
|
36
|
+
# merge_spec_quality_output: coverage/polyrun-spec-quality.json
|
|
37
|
+
|
|
38
|
+
# Uncomment and edit when using Postgres template + per-shard DB names from polyrun env.
|
|
39
|
+
# CloneShards / polyrun start auto provision is PostgreSQL-only. For mysql2 (or other adapters),
|
|
40
|
+
# keep template_db + shard_db_pattern for URL shaping, set start.databases: false, and provision shards in prepare.
|
|
41
|
+
# databases:
|
|
42
|
+
# template_db: my_app_template
|
|
43
|
+
# shard_db_pattern: "my_app_test_%{shard}"
|
|
44
|
+
# postgresql:
|
|
45
|
+
# host: localhost
|
|
46
|
+
# username: postgres
|
|
47
|
+
# connections:
|
|
48
|
+
# - name: analytics
|
|
49
|
+
# template_db: my_app_analytics_template # second migrate + CREATE … TEMPLATE for parallel tests
|
|
50
|
+
# shard_db_pattern: "my_app_analytics_test_%{shard}"
|
|
51
|
+
# env_key: ANALYTICS_DATABASE_URL # must match database.yml / Rails multi-db
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by: polyrun init --profile rails-prepare-task
|
|
4
|
+
# Runs once before parallel workers. Skip: POLYRUN_SKIP_PREPARE=1 (legacy: POLYRUN_START_SKIP_PREPARE=1).
|
|
5
|
+
|
|
6
|
+
namespace :polyrun do
|
|
7
|
+
desc "One-shot Polyrun prepare (delegates to `polyrun prepare`)"
|
|
8
|
+
task prepare: :environment do
|
|
9
|
+
skip = %w[1 true yes].include?(ENV["POLYRUN_SKIP_PREPARE"].to_s.downcase) ||
|
|
10
|
+
%w[1 true yes].include?(ENV["POLYRUN_START_SKIP_PREPARE"].to_s.downcase)
|
|
11
|
+
next if skip
|
|
12
|
+
|
|
13
|
+
ok = system({"RUBYOPT" => nil}, "bundle", "exec", "polyrun", "prepare")
|
|
14
|
+
abort "polyrun prepare failed" unless ok
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
require_relative "../debug"
|
|
4
|
+
require_relative "stats"
|
|
5
|
+
require_relative "variance_report"
|
|
6
|
+
|
|
7
|
+
module Polyrun
|
|
8
|
+
module Timing
|
|
9
|
+
module Merge
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
def merge_files(paths)
|
|
13
|
+
merged = {}
|
|
14
|
+
paths.each do |p|
|
|
15
|
+
data = JSON.parse(File.read(p))
|
|
16
|
+
next unless data.is_a?(Hash)
|
|
17
|
+
|
|
18
|
+
data.each do |file, sec|
|
|
19
|
+
f = file.to_s
|
|
20
|
+
entry = sec
|
|
21
|
+
merged[f] = merged.key?(f) ? Stats.merge_entries(merged[f], entry) : Stats.normalize_entry(entry)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
merged
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def merge_and_write(paths, output_path)
|
|
28
|
+
Polyrun::Debug.log_kv(merge_timing: "merge_and_write", input_count: paths.size, output_path: output_path)
|
|
29
|
+
merged = Polyrun::Debug.time("Timing::Merge.merge_files") { merge_files(paths) }
|
|
30
|
+
Polyrun::Debug.time("Timing::Merge.write JSON") { File.write(output_path, JSON.pretty_generate(merged)) }
|
|
31
|
+
Timing::VarianceReport.emit_warnings!(merged)
|
|
32
|
+
merged
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
require "rspec/core/formatters"
|
|
4
|
+
|
|
5
|
+
module Polyrun
|
|
6
|
+
module Timing
|
|
7
|
+
# Experimental: records +absolute_path:line_number+ => wall seconds per example for
|
|
8
|
+
# {Partition::Plan} +timing_granularity: :example+ and +merge-timing+.
|
|
9
|
+
#
|
|
10
|
+
# Use after RSpec is loaded:
|
|
11
|
+
# require "polyrun/timing/rspec_example_formatter"
|
|
12
|
+
# RSpec.configure { |c| c.add_formatter Polyrun::Timing::RSpecExampleFormatter }
|
|
13
|
+
# Or {Polyrun::RSpecSupport.install_example_timing!} (+output_path:+ avoids touching +ENV+).
|
|
14
|
+
#
|
|
15
|
+
# Default output path: +ENV["POLYRUN_EXAMPLE_TIMING_OUT"]+ if set, else +polyrun_timing_examples.json+.
|
|
16
|
+
class RSpecExampleFormatter
|
|
17
|
+
::RSpec::Core::Formatters.register self, :example_finished, :close
|
|
18
|
+
|
|
19
|
+
def initialize(output)
|
|
20
|
+
@output = output
|
|
21
|
+
@times = {}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def example_finished(notification)
|
|
25
|
+
ex = notification.example
|
|
26
|
+
return if ex.pending?
|
|
27
|
+
|
|
28
|
+
result = ex.execution_result
|
|
29
|
+
t = result.run_time
|
|
30
|
+
return unless t
|
|
31
|
+
|
|
32
|
+
path = example_absolute_path(ex)
|
|
33
|
+
return unless path
|
|
34
|
+
|
|
35
|
+
line = ex.metadata[:line_number]
|
|
36
|
+
return unless line
|
|
37
|
+
|
|
38
|
+
key = "#{File.expand_path(path)}:#{line}"
|
|
39
|
+
cur = @times[key]
|
|
40
|
+
@times[key] = cur ? [cur, t].max : t
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def close(_notification)
|
|
44
|
+
File.write(timing_output_path, JSON.pretty_generate(@times))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Override in a subclass from {Polyrun::RSpecSupport.install_example_timing!(output_path: ...)}.
|
|
48
|
+
def timing_output_path
|
|
49
|
+
ENV["POLYRUN_EXAMPLE_TIMING_OUT"] || "polyrun_timing_examples.json"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def example_absolute_path(example)
|
|
55
|
+
metadata = example.metadata
|
|
56
|
+
metadata[:absolute_file_path] || metadata[:file_path] || metadata[:absolute_path]
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module Polyrun
|
|
2
|
+
module Timing
|
|
3
|
+
# Normalizes scalar or object timing entries for merge and binpack weight lookup.
|
|
4
|
+
module Stats
|
|
5
|
+
STAT_KEYS = %w[last_seconds min max mean p95 runs failures timeouts].freeze
|
|
6
|
+
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
def normalize_entry(value)
|
|
10
|
+
case value
|
|
11
|
+
when Hash
|
|
12
|
+
normalize_hash(value)
|
|
13
|
+
else
|
|
14
|
+
sec = value.to_f
|
|
15
|
+
{
|
|
16
|
+
"last_seconds" => sec,
|
|
17
|
+
"min" => sec,
|
|
18
|
+
"max" => sec,
|
|
19
|
+
"mean" => sec,
|
|
20
|
+
"p95" => sec,
|
|
21
|
+
"runs" => 1,
|
|
22
|
+
"failures" => 0,
|
|
23
|
+
"timeouts" => 0
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity -- timing hash key coercion
|
|
29
|
+
def normalize_hash(h)
|
|
30
|
+
out = {}
|
|
31
|
+
sec = h["last_seconds"] || h[:last_seconds] || h["seconds"] || h[:seconds]
|
|
32
|
+
sec = sec.to_f if sec
|
|
33
|
+
mean = (h["mean"] || h[:mean] || sec)&.to_f
|
|
34
|
+
out["last_seconds"] = (sec || mean || 0.0).to_f
|
|
35
|
+
out["min"] = (h["min"] || h[:min] || out["last_seconds"]).to_f
|
|
36
|
+
out["max"] = (h["max"] || h[:max] || out["last_seconds"]).to_f
|
|
37
|
+
out["mean"] = (mean || out["last_seconds"]).to_f
|
|
38
|
+
out["p95"] = (h["p95"] || h[:p95] || out["max"]).to_f
|
|
39
|
+
out["runs"] = Integer(h["runs"] || h[:runs] || 1)
|
|
40
|
+
out["failures"] = Integer(h["failures"] || h[:failures] || 0)
|
|
41
|
+
out["timeouts"] = Integer(h["timeouts"] || h[:timeouts] || 0)
|
|
42
|
+
out
|
|
43
|
+
end
|
|
44
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
45
|
+
|
|
46
|
+
def binpack_weight(entry)
|
|
47
|
+
h = normalize_entry(entry)
|
|
48
|
+
h["last_seconds"].positive? ? h["last_seconds"] : h["mean"]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# rubocop:disable Metrics/AbcSize -- weighted mean merge
|
|
52
|
+
def merge_entries(a, b)
|
|
53
|
+
ha = normalize_entry(a)
|
|
54
|
+
hb = normalize_entry(b)
|
|
55
|
+
runs = ha["runs"] + hb["runs"]
|
|
56
|
+
mean =
|
|
57
|
+
if runs.positive?
|
|
58
|
+
((ha["mean"] * ha["runs"]) + (hb["mean"] * hb["runs"])) / runs.to_f
|
|
59
|
+
else
|
|
60
|
+
0.0
|
|
61
|
+
end
|
|
62
|
+
{
|
|
63
|
+
"last_seconds" => [ha["last_seconds"], hb["last_seconds"]].max,
|
|
64
|
+
"min" => [ha["min"], hb["min"]].min,
|
|
65
|
+
"max" => [ha["max"], hb["max"]].max,
|
|
66
|
+
"mean" => mean,
|
|
67
|
+
"p95" => [ha["p95"], hb["p95"]].max,
|
|
68
|
+
"runs" => runs,
|
|
69
|
+
"failures" => ha["failures"] + hb["failures"],
|
|
70
|
+
"timeouts" => ha["timeouts"] + hb["timeouts"]
|
|
71
|
+
}
|
|
72
|
+
end
|
|
73
|
+
# rubocop:enable Metrics/AbcSize
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|