2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-08-17 18:04:11 +08:00

DEV: Fix core backend CI tests timing out (#34281)

The test cases added in 470b2891c5 caused
core backend tests to start timing out on CI because MessageBus messages
were being processed in a background thread outside of the current
database transation.

We are currently working around the problem by updating the test cases
to just assert that the right MessageBus message is being published.
This commit is contained in:
Alan Guo Xiang Tan 2025-08-13 16:06:19 +08:00 committed by GitHub
parent c158301acb
commit 2b6b6226b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 60 deletions

View file

@ -448,11 +448,13 @@ module SiteSettingExtension
end
end
SITE_SETTINGS_CHANNEL = "/site_settings"
def ensure_listen_for_changes
return if @listen_for_changes == false
unless @subscribed
MessageBus.subscribe("/site_settings") do |message|
MessageBus.subscribe(SITE_SETTINGS_CHANNEL) do |message|
process_message(message) if message.data["process"] != process_id
end

View file

@ -21,8 +21,6 @@ class SiteSettings::LocalProcessProvider
end
end
attr_accessor :model
def settings
@settings[current_site] ||= {}
end
@ -49,10 +47,6 @@ class SiteSettings::LocalProcessProvider
end
setting.value = value.to_s
# So we can simulate the MessageBus notifications
# done by the DbProvider
@model.notify_changed! if @model
setting
end

View file

@ -41,12 +41,6 @@ RSpec.describe SiteSettingExtension do
new_settings(provider_local)
end
after do
settings.provider.model = nil
settings.listen_for_changes = false
settings2.listen_for_changes = false
end
it "does not leak state cause changes are not linked" do
t1 =
Thread.new do
@ -72,7 +66,12 @@ RSpec.describe SiteSettingExtension do
t2.join
end
describe "refresh!" do
describe ".refresh!" do
it "ensures that the right MessageBus subscription has been set up" do
settings.expects(:ensure_listen_for_changes).once
settings.refresh!
end
it "will reset to default if provider vanishes" do
settings.setting(:hello, 1)
settings.hello = 100
@ -110,30 +109,6 @@ RSpec.describe SiteSettingExtension do
expect(settings2.hello).to eq(99)
end
it "publishes changes across processes" do
MessageBus.on
# Only need to do this once, since both settings will use the same provider. Doing it twice leads to confusion with MessageBus
settings.provider.model = settings
settings.listen_for_changes = true
settings2.listen_for_changes = true
settings.refresh!
settings2.refresh!
settings.setting(:hello, 1)
settings2.setting(:hello, 1)
settings.hello = 100
expect(settings2.hello).to eq(100)
settings.hello = 99
try_until_success(frequency: 0.5) { expect(settings2.hello).to eq(99) }
end
it "does not override types in the type supervisor" do
settings.setting(:foo, "bar")
settings.provider.save(:foo, "bar", SiteSetting.types[:enum])
@ -1078,36 +1053,29 @@ RSpec.describe SiteSettingExtension do
expect(SiteSetting.search_experience(theme_id: theme_2.id)).to eq("search_field")
end
it "publishes changes across processes" do
MessageBus.on
it "publishes the right MessageBus message when a theme site setting is updated" do
settings_tss_instance_1 = new_settings(provider_local)
settings_tss_instance_2 = new_settings(provider_local)
settings_tss_instance_1.listen_for_changes = true
settings_tss_instance_2.listen_for_changes = true
settings_tss_instance_1.load_settings(File.join(Rails.root, "config", "site_settings.yml"))
settings_tss_instance_2.load_settings(File.join(Rails.root, "config", "site_settings.yml"))
settings_tss_instance_1.refresh!
settings_tss_instance_2.refresh!
expect(settings_tss_instance_1.enable_welcome_banner(theme_id: theme_1.id)).to eq(false)
expect(settings_tss_instance_2.enable_welcome_banner(theme_id: theme_1.id)).to eq(false)
tss_1.update!(value: true)
settings_tss_instance_1.change_themeable_site_setting(
theme_1.id,
:enable_welcome_banner,
true,
)
# Get through the MessageBus queue
try_until_success(frequency: 0.5) do
expect(settings_tss_instance_1.enable_welcome_banner(theme_id: theme_1.id)).to eq(true)
expect(settings_tss_instance_2.enable_welcome_banner(theme_id: theme_1.id)).to eq(true)
end
messages =
MessageBus.track_publish(described_class::SITE_SETTINGS_CHANNEL) do
settings_tss_instance_1.change_themeable_site_setting(
theme_1.id,
:enable_welcome_banner,
true,
)
end
expect(messages.length).to eq(1)
message = messages.first
expect(message.data[:process]).to eq(settings_tss_instance_1.process_id)
end
describe ".theme_site_settings_json_uncached" do

View file

@ -20,7 +20,10 @@ RSpec.describe SiteSettings::DbProvider do
expect(provider.all.length).to eq(0)
expect(provider.find("test")).to eq(nil)
SiteSetting.expects(:notify_changed!).at_least_once
provider.save("test", "one", 1)
found = provider.find("test")
expect_same_setting(found, setting.new("test", "one", 1))