Skip to content

Commit e66594d

Browse files
authored
Release benchmarks should also filter by repo_id so we don't get mixed results from different repos (#263)
* Release benchmarks should also filter by repo_id so we don't get mixed results * Fix rubocop
1 parent 176a982 commit e66594d

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

app/controllers/repos_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def releases
3131
unless @benchmark.blank?
3232
@charts = ips_first(@benchmark.benchmark_result_types).map do |benchmark_result_type|
3333
benchmark_runs = BenchmarkRun.fetch_release_benchmark_runs(
34-
@benchmark.category, benchmark_result_type
34+
@benchmark, benchmark_result_type
3535
)
3636

3737
next if benchmark_runs.empty?

app/models/benchmark_run.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ class BenchmarkRun < ApplicationRecord
2929
.limit(limit)
3030
}
3131

32-
scope :fetch_release_benchmark_runs, ->(form_result_type, benchmark_result_type) {
32+
scope :fetch_release_benchmark_runs, ->(result_type, benchmark_result_type) {
3333
joins(:benchmark_type)
34+
.joins('INNER JOIN releases ON releases.id = benchmark_runs.initiator_id')
3435
.includes(:initiator)
3536
.where(
36-
benchmark_types: { category: form_result_type },
37+
benchmark_types: { category: result_type.category },
3738
benchmark_result_type: benchmark_result_type,
3839
initiator_type: 'Release',
40+
releases: { repo_id: result_type.repo_id },
3941
validity: true
4042
)
4143
}

test/models/benchmark_run_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,36 @@ class BenchmarkRunTest < ActiveSupport::TestCase
4040
BenchmarkRun.latest_commit_benchmark_run(benchmark_type, benchmark_result_type)
4141
)
4242
end
43+
44+
test '.fetch_release_benchmark_runs' do
45+
script_url = 'https://raw.githubusercontent.com/org/repo/master/script/bench.rb'
46+
47+
ruby = create(:repo, name: 'ruby')
48+
rails = create(:repo, name: 'rails')
49+
50+
ruby_release = create(:release, repo: ruby, version: '2.6.2')
51+
rails_release = create(:release, repo: rails, version: '6.0.0')
52+
53+
ruby_benchmark_type = create(:benchmark_type, category: 'discourse_home', repo: ruby, script_url: script_url)
54+
rails_benchmark_type = create(:benchmark_type, category: 'discourse_home', repo: rails, script_url: script_url)
55+
56+
benchmark_result_type = create(:benchmark_result_type)
57+
ruby_benchmark_run = create(:release_benchmark_run,
58+
benchmark_result_type: benchmark_result_type,
59+
benchmark_type: ruby_benchmark_type,
60+
initiator: ruby_release
61+
)
62+
rails_benchmark_run = create(:release_benchmark_run,
63+
benchmark_result_type: benchmark_result_type,
64+
benchmark_type: rails_benchmark_type,
65+
initiator: rails_release
66+
)
67+
ruby_result = BenchmarkRun.fetch_release_benchmark_runs(ruby_benchmark_type, benchmark_result_type)
68+
assert_equal(1, ruby_result.size)
69+
assert_equal(ruby_benchmark_run.id, ruby_result.first.id)
70+
71+
rails_result = BenchmarkRun.fetch_release_benchmark_runs(rails_benchmark_type, benchmark_result_type)
72+
assert_equal(1, rails_result.size)
73+
assert_equal(rails_benchmark_run.id, rails_result.first.id)
74+
end
4375
end

0 commit comments

Comments
 (0)