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