mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 22:21:55 +08:00
DEV: Split slow test in multiple smaller tests (#28646)
* DEV: Split slow test in multiple smaller tests This might be faster because the smaller chunks of the test may run in parallel. * DEV: Fabricate reviewables only once
This commit is contained in:
parent
ca26099a8d
commit
1f206349fd
|
@ -1,23 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Jobs::ReviewablePriorities do
|
||||
it "needs returns 0s with no existing reviewables" do
|
||||
Jobs::ReviewablePriorities.new.execute({})
|
||||
|
||||
expect_min_score(:low, 0.0)
|
||||
expect_min_score(:medium, 0.0)
|
||||
expect_min_score(:high, 0.0)
|
||||
expect(Reviewable.score_required_to_hide_post).to eq(8.33)
|
||||
end
|
||||
|
||||
fab!(:user_0) { Fabricate(:user) }
|
||||
fab!(:user_1) { Fabricate(:user) }
|
||||
|
||||
def create_reviewables(count, status: :approved)
|
||||
minimum_threshold = SiteSetting.reviewable_low_priority_threshold
|
||||
(1..count).each { |i| create_with_score(minimum_threshold + i) }
|
||||
end
|
||||
|
||||
def create_with_score(score, status: :approved)
|
||||
Fabricate(:reviewable_flagged_post, status: Reviewable.statuses[status]).tap do |reviewable|
|
||||
reviewable.add_score(user_0, PostActionType.types[:off_topic])
|
||||
|
@ -26,9 +12,7 @@ RSpec.describe Jobs::ReviewablePriorities do
|
|||
end
|
||||
end
|
||||
|
||||
it "needs a minimum amount of reviewables before it calculates anything" do
|
||||
create_reviewables(5)
|
||||
|
||||
it "needs returns 0s with no existing reviewables" do
|
||||
Jobs::ReviewablePriorities.new.execute({})
|
||||
|
||||
expect_min_score(:low, 0.0)
|
||||
|
@ -37,46 +21,67 @@ RSpec.describe Jobs::ReviewablePriorities do
|
|||
expect(Reviewable.score_required_to_hide_post).to eq(8.33)
|
||||
end
|
||||
|
||||
context "when there are enough reviewables" do
|
||||
let(:medium_threshold) { 8.0 }
|
||||
let(:high_threshold) { 13.0 }
|
||||
let(:score_to_hide_post) { 8.66 }
|
||||
|
||||
it "will set priorities based on the maximum score" do
|
||||
create_reviewables(Jobs::ReviewablePriorities.min_reviewables)
|
||||
|
||||
Jobs::ReviewablePriorities.new.execute({})
|
||||
|
||||
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
||||
expect_min_score(:medium, medium_threshold)
|
||||
expect_min_score(:high, high_threshold)
|
||||
expect(Reviewable.score_required_to_hide_post).to eq(score_to_hide_post)
|
||||
context "with reviewables" do
|
||||
# Generate all reviewables first because they take a lot of time
|
||||
fab!(:reviewables) do
|
||||
(1..Jobs::ReviewablePriorities.min_reviewables).map do |i|
|
||||
create_with_score(SiteSetting.reviewable_low_priority_threshold + i)
|
||||
end
|
||||
end
|
||||
|
||||
it "ignore negative scores when calculating priorities" do
|
||||
create_reviewables(Jobs::ReviewablePriorities.min_reviewables)
|
||||
negative_score = -9
|
||||
10.times { create_with_score(negative_score) }
|
||||
# This reviewable will be ignored in most tests
|
||||
fab!(:other_reviewable) { create_with_score(0) }
|
||||
|
||||
it "needs a minimum amount of reviewables before it calculates anything" do
|
||||
reviewables[0].destroy!
|
||||
other_reviewable.destroy!
|
||||
|
||||
Jobs::ReviewablePriorities.new.execute({})
|
||||
|
||||
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
||||
expect_min_score(:medium, medium_threshold)
|
||||
expect_min_score(:high, high_threshold)
|
||||
expect(Reviewable.score_required_to_hide_post).to eq(score_to_hide_post)
|
||||
expect_min_score(:low, 0.0)
|
||||
expect_min_score(:medium, 0.0)
|
||||
expect_min_score(:high, 0.0)
|
||||
expect(Reviewable.score_required_to_hide_post).to eq(8.33)
|
||||
end
|
||||
|
||||
it "ignores non-approved reviewables" do
|
||||
create_reviewables(Jobs::ReviewablePriorities.min_reviewables)
|
||||
low_score = 2
|
||||
10.times { create_with_score(low_score, status: :pending) }
|
||||
context "when there are enough reviewables" do
|
||||
let(:medium_threshold) { 8.0 }
|
||||
let(:high_threshold) { 13.0 }
|
||||
let(:score_to_hide_post) { 8.66 }
|
||||
|
||||
Jobs::ReviewablePriorities.new.execute({})
|
||||
it "will set priorities based on the maximum score" do
|
||||
other_reviewable.destroy!
|
||||
Jobs::ReviewablePriorities.new.execute({})
|
||||
|
||||
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
||||
expect_min_score(:medium, medium_threshold)
|
||||
expect_min_score(:high, high_threshold)
|
||||
expect(Reviewable.score_required_to_hide_post).to eq(score_to_hide_post)
|
||||
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
||||
expect_min_score(:medium, medium_threshold)
|
||||
expect_min_score(:high, high_threshold)
|
||||
expect(Reviewable.score_required_to_hide_post).to eq(score_to_hide_post)
|
||||
end
|
||||
|
||||
it "ignore negative scores when calculating priorities" do
|
||||
negative_score = -9
|
||||
other_reviewable.update!(score: negative_score)
|
||||
|
||||
Jobs::ReviewablePriorities.new.execute({})
|
||||
|
||||
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
||||
expect_min_score(:medium, medium_threshold)
|
||||
expect_min_score(:high, high_threshold)
|
||||
expect(Reviewable.score_required_to_hide_post).to eq(score_to_hide_post)
|
||||
end
|
||||
|
||||
it "ignores non-approved reviewables" do
|
||||
low_score = 2
|
||||
other_reviewable.update!(score: low_score, status: Reviewable.statuses[:pending])
|
||||
|
||||
Jobs::ReviewablePriorities.new.execute({})
|
||||
|
||||
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
||||
expect_min_score(:medium, medium_threshold)
|
||||
expect_min_score(:high, high_threshold)
|
||||
expect(Reviewable.score_required_to_hide_post).to eq(score_to_hide_post)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -859,63 +859,59 @@ RSpec.describe Stylesheet::Manager do
|
|||
%w[desktop mobile admin wizard desktop_rtl mobile_rtl admin_rtl wizard_rtl]
|
||||
end
|
||||
|
||||
before { STDERR.stubs(:write) }
|
||||
let(:theme_targets) { %i[desktop_theme mobile_theme] }
|
||||
|
||||
before do
|
||||
STDERR.stubs(:write)
|
||||
StylesheetCache.destroy_all
|
||||
default_theme.set_default!
|
||||
end
|
||||
|
||||
after do
|
||||
STDERR.unstub(:write)
|
||||
Stylesheet::Manager.rm_cache_folder
|
||||
end
|
||||
|
||||
it "correctly generates precompiled CSS" do
|
||||
scheme1 = ColorScheme.create!(name: "scheme1")
|
||||
scheme2 = ColorScheme.create!(name: "scheme2")
|
||||
theme_targets = %i[desktop_theme mobile_theme]
|
||||
fab!(:scheme1) { ColorScheme.create!(name: "scheme1") }
|
||||
fab!(:scheme2) { ColorScheme.create!(name: "scheme2") }
|
||||
|
||||
Theme.update_all(user_selectable: false)
|
||||
user_theme = Fabricate(:theme, user_selectable: true, color_scheme: scheme1)
|
||||
default_theme = Fabricate(:theme, user_selectable: true, color_scheme: scheme2)
|
||||
fab!(:user_theme) { Fabricate(:theme, user_selectable: true, color_scheme: scheme1) }
|
||||
fab!(:default_theme) { Fabricate(:theme, user_selectable: true, color_scheme: scheme2) }
|
||||
fab!(:child_theme) do
|
||||
Fabricate(:theme).tap do |t|
|
||||
t.component = true
|
||||
t.save!
|
||||
user_theme.add_relative_theme!(:child, t)
|
||||
end
|
||||
end
|
||||
fab!(:child_theme_with_css) do
|
||||
Fabricate(:theme).tap do |t|
|
||||
t.component = true
|
||||
t.set_field(target: :common, name: :scss, value: "body { background: green }")
|
||||
t.save!
|
||||
user_theme.add_relative_theme!(:child, t)
|
||||
default_theme.add_relative_theme!(:child, t)
|
||||
end
|
||||
end
|
||||
|
||||
child_theme =
|
||||
Fabricate(:theme).tap do |t|
|
||||
t.component = true
|
||||
t.save!
|
||||
user_theme.add_relative_theme!(:child, t)
|
||||
end
|
||||
it "generates precompiled CSS - only core" do
|
||||
capture_output(:stderr) { Stylesheet::Manager.precompile_css }
|
||||
|
||||
child_theme_with_css =
|
||||
Fabricate(:theme).tap do |t|
|
||||
t.component = true
|
||||
expect(StylesheetCache.pluck(:target)).to contain_exactly(*core_targets)
|
||||
end
|
||||
|
||||
t.set_field(target: :common, name: :scss, value: "body { background: green }")
|
||||
|
||||
t.save!
|
||||
|
||||
user_theme.add_relative_theme!(:child, t)
|
||||
default_theme.add_relative_theme!(:child, t)
|
||||
end
|
||||
|
||||
default_theme.set_default!
|
||||
|
||||
StylesheetCache.destroy_all
|
||||
|
||||
# only core
|
||||
output = capture_output(:stderr) { Stylesheet::Manager.precompile_css }
|
||||
|
||||
results = StylesheetCache.pluck(:target)
|
||||
expect(results).to contain_exactly(*core_targets)
|
||||
|
||||
StylesheetCache.destroy_all
|
||||
|
||||
# only themes
|
||||
it "generates precompiled CSS - only themes" do
|
||||
output = capture_output(:stderr) { Stylesheet::Manager.precompile_theme_css }
|
||||
|
||||
# Ensure we force compile each theme only once
|
||||
expect(output.scan(/#{child_theme_with_css.name}/).length).to eq(2)
|
||||
results = StylesheetCache.pluck(:target)
|
||||
expect(results.size).to eq(22) # (3 themes * 2 targets) + 16 color schemes (2 themes * 8 color schemes (7 defaults + 1 theme scheme))
|
||||
expect(StylesheetCache.count).to eq(22) # (3 themes * 2 targets) + 16 color schemes (2 themes * 8 color schemes (7 defaults + 1 theme scheme))
|
||||
end
|
||||
|
||||
# themes + core
|
||||
it "generates precompiled CSS - core and themes" do
|
||||
Stylesheet::Manager.precompile_css
|
||||
Stylesheet::Manager.precompile_theme_css
|
||||
|
||||
results = StylesheetCache.pluck(:target)
|
||||
expect(results.size).to eq(30) # 11 core targets + 9 theme + 10 color schemes
|
||||
|
||||
|
@ -924,13 +920,14 @@ RSpec.describe Stylesheet::Manager do
|
|||
results.count { |target| target =~ /^#{tar}_(#{user_theme.id}|#{default_theme.id})$/ },
|
||||
).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
it "correctly generates precompiled CSS - core and themes and no default theme" do
|
||||
Theme.clear_default!
|
||||
StylesheetCache.destroy_all
|
||||
|
||||
# themes + core with no theme set as default
|
||||
Stylesheet::Manager.precompile_css
|
||||
Stylesheet::Manager.precompile_theme_css
|
||||
|
||||
results = StylesheetCache.pluck(:target)
|
||||
expect(results.size).to eq(30) # 11 core targets + 9 theme + 10 color schemes
|
||||
|
||||
|
@ -948,33 +945,24 @@ RSpec.describe Stylesheet::Manager do
|
|||
image = file_from_fixtures("logo.png")
|
||||
upload = UploadCreator.new(image, "logo.png").create_for(-1)
|
||||
|
||||
scheme = ColorScheme.create!(name: "scheme")
|
||||
theme_targets = %i[desktop_theme mobile_theme]
|
||||
ThemeField.create!(
|
||||
theme_id: default_theme.id,
|
||||
target_id: Theme.targets[:common],
|
||||
name: "logo",
|
||||
value: "",
|
||||
upload_id: upload.id,
|
||||
type_id: ThemeField.types[:theme_upload_var],
|
||||
)
|
||||
|
||||
default_theme =
|
||||
Fabricate(:theme, color_scheme: scheme).tap do |t|
|
||||
field =
|
||||
ThemeField.create!(
|
||||
theme_id: t.id,
|
||||
target_id: Theme.targets[:common],
|
||||
name: "logo",
|
||||
value: "",
|
||||
upload_id: upload.id,
|
||||
type_id: ThemeField.types[:theme_upload_var],
|
||||
)
|
||||
default_theme.set_field(
|
||||
target: :common,
|
||||
name: :scss,
|
||||
value: "body { background: url($logo); border: 3px solid green; }",
|
||||
)
|
||||
|
||||
t.set_field(
|
||||
target: :common,
|
||||
name: :scss,
|
||||
value: "body { background: url($logo); border: 3px solid green; }",
|
||||
)
|
||||
default_theme.save!
|
||||
|
||||
t.save!
|
||||
end
|
||||
|
||||
default_theme.set_default!
|
||||
upload.destroy!
|
||||
StylesheetCache.destroy_all
|
||||
|
||||
Stylesheet::Manager.precompile_theme_css
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user