mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:11:38 +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,8 +12,29 @@ RSpec.describe Jobs::ReviewablePriorities do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# 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
|
it "needs a minimum amount of reviewables before it calculates anything" do
|
||||||
create_reviewables(5)
|
reviewables[0].destroy!
|
||||||
|
other_reviewable.destroy!
|
||||||
|
|
||||||
Jobs::ReviewablePriorities.new.execute({})
|
Jobs::ReviewablePriorities.new.execute({})
|
||||||
|
|
||||||
|
@ -43,8 +50,7 @@ RSpec.describe Jobs::ReviewablePriorities do
|
||||||
let(:score_to_hide_post) { 8.66 }
|
let(:score_to_hide_post) { 8.66 }
|
||||||
|
|
||||||
it "will set priorities based on the maximum score" do
|
it "will set priorities based on the maximum score" do
|
||||||
create_reviewables(Jobs::ReviewablePriorities.min_reviewables)
|
other_reviewable.destroy!
|
||||||
|
|
||||||
Jobs::ReviewablePriorities.new.execute({})
|
Jobs::ReviewablePriorities.new.execute({})
|
||||||
|
|
||||||
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
||||||
|
@ -54,9 +60,8 @@ RSpec.describe Jobs::ReviewablePriorities do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "ignore negative scores when calculating priorities" do
|
it "ignore negative scores when calculating priorities" do
|
||||||
create_reviewables(Jobs::ReviewablePriorities.min_reviewables)
|
|
||||||
negative_score = -9
|
negative_score = -9
|
||||||
10.times { create_with_score(negative_score) }
|
other_reviewable.update!(score: negative_score)
|
||||||
|
|
||||||
Jobs::ReviewablePriorities.new.execute({})
|
Jobs::ReviewablePriorities.new.execute({})
|
||||||
|
|
||||||
|
@ -67,9 +72,8 @@ RSpec.describe Jobs::ReviewablePriorities do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "ignores non-approved reviewables" do
|
it "ignores non-approved reviewables" do
|
||||||
create_reviewables(Jobs::ReviewablePriorities.min_reviewables)
|
|
||||||
low_score = 2
|
low_score = 2
|
||||||
10.times { create_with_score(low_score, status: :pending) }
|
other_reviewable.update!(score: low_score, status: Reviewable.statuses[:pending])
|
||||||
|
|
||||||
Jobs::ReviewablePriorities.new.execute({})
|
Jobs::ReviewablePriorities.new.execute({})
|
||||||
|
|
||||||
|
@ -79,6 +83,7 @@ RSpec.describe Jobs::ReviewablePriorities do
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def expect_min_score(priority, score)
|
def expect_min_score(priority, score)
|
||||||
expect(Reviewable.min_score_for_priority(priority)).to eq(score)
|
expect(Reviewable.min_score_for_priority(priority)).to eq(score)
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
child_theme =
|
|
||||||
Fabricate(:theme).tap do |t|
|
Fabricate(:theme).tap do |t|
|
||||||
t.component = true
|
t.component = true
|
||||||
t.save!
|
t.save!
|
||||||
user_theme.add_relative_theme!(:child, t)
|
user_theme.add_relative_theme!(:child, t)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
child_theme_with_css =
|
fab!(:child_theme_with_css) do
|
||||||
Fabricate(:theme).tap do |t|
|
Fabricate(:theme).tap do |t|
|
||||||
t.component = true
|
t.component = true
|
||||||
|
|
||||||
t.set_field(target: :common, name: :scss, value: "body { background: green }")
|
t.set_field(target: :common, name: :scss, value: "body { background: green }")
|
||||||
|
|
||||||
t.save!
|
t.save!
|
||||||
|
|
||||||
user_theme.add_relative_theme!(:child, t)
|
user_theme.add_relative_theme!(:child, t)
|
||||||
default_theme.add_relative_theme!(:child, t)
|
default_theme.add_relative_theme!(:child, t)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
default_theme.set_default!
|
it "generates precompiled CSS - only core" do
|
||||||
|
capture_output(:stderr) { Stylesheet::Manager.precompile_css }
|
||||||
|
|
||||||
StylesheetCache.destroy_all
|
expect(StylesheetCache.pluck(:target)).to contain_exactly(*core_targets)
|
||||||
|
end
|
||||||
|
|
||||||
# only core
|
it "generates precompiled CSS - only themes" do
|
||||||
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,14 +945,8 @@ 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")
|
|
||||||
theme_targets = %i[desktop_theme mobile_theme]
|
|
||||||
|
|
||||||
default_theme =
|
|
||||||
Fabricate(:theme, color_scheme: scheme).tap do |t|
|
|
||||||
field =
|
|
||||||
ThemeField.create!(
|
ThemeField.create!(
|
||||||
theme_id: t.id,
|
theme_id: default_theme.id,
|
||||||
target_id: Theme.targets[:common],
|
target_id: Theme.targets[:common],
|
||||||
name: "logo",
|
name: "logo",
|
||||||
value: "",
|
value: "",
|
||||||
|
@ -963,18 +954,15 @@ RSpec.describe Stylesheet::Manager do
|
||||||
type_id: ThemeField.types[:theme_upload_var],
|
type_id: ThemeField.types[:theme_upload_var],
|
||||||
)
|
)
|
||||||
|
|
||||||
t.set_field(
|
default_theme.set_field(
|
||||||
target: :common,
|
target: :common,
|
||||||
name: :scss,
|
name: :scss,
|
||||||
value: "body { background: url($logo); border: 3px solid green; }",
|
value: "body { background: url($logo); border: 3px solid green; }",
|
||||||
)
|
)
|
||||||
|
|
||||||
t.save!
|
default_theme.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