DEV: Stablize the multisite tests.

DEV: Stablize the multisite tests.

SiteSettingExtension triggers message bus which re-establishes a DB connection in SiteSettingExtension#process_message. That happens concurrently and a test that requires a connection to the db will fail when the reconnection is happening.

diff --git a/lib/site_setting_extension.rb b/lib/site_setting_extension.rb
index abdafe7..08c775d 100644
--- a/lib/site_setting_extension.rb
+++ b/lib/site_setting_extension.rb
@@ -301,22 +301,22 @@ module SiteSettingExtension
 
     unless @subscribed
       MessageBus.subscribe("/site_settings") do |message|
-        process_message(message)
+        if message.data["process"] != process_id
+          process_message(message)
+        end
       end
+
       @subscribed = true
     end
   end
 
   def process_message(message)
-    data = message.data
-    if data["process"] != process_id
-      begin
-        @last_message_processed = message.global_id
-        MessageBus.on_connect.call(message.site_id)
-        refresh!
-      ensure
-        MessageBus.on_disconnect.call(message.site_id)
-      end
+    begin
+      @last_message_processed = message.global_id
+      MessageBus.on_connect.call(message.site_id)
+      refresh!
+    ensure
+      MessageBus.on_disconnect.call(message.site_id)
     end
   end
 
diff --git a/spec/components/site_setting_extension_spec.rb b/spec/components/site_setting_extension_spec.rb
index 858a501..a4a33e6 100644
--- a/spec/components/site_setting_extension_spec.rb
+++ b/spec/components/site_setting_extension_spec.rb
@@ -42,16 +42,6 @@ describe SiteSettingExtension do
     SiteSettings::LocalProcessProvider.new
   end
 
-  def new_settings(provider)
-    # we want to avoid leaking a big pile of MessageBus subscriptions here (1 per class)
-    # so we set listen_for_changes to false
-    Class.new do
-      extend SiteSettingExtension
-      self.listen_for_changes = false
-      self.provider = provider
-    end
-  end
-
   let :settings do
     new_settings(provider_local)
   end
diff --git a/spec/components/site_settings/defaults_provider_spec.rb b/spec/components/site_settings/defaults_provider_spec.rb
index 948f66e..463c197 100644
--- a/spec/components/site_settings/defaults_provider_spec.rb
+++ b/spec/components/site_settings/defaults_provider_spec.rb
@@ -14,14 +14,6 @@ describe SiteSettings::DefaultsProvider do
     MessageBus.on
   end
 
-  def new_settings(provider)
-    Class.new do
-      extend SiteSettingExtension
-      self.listen_for_changes = false
-      self.provider = provider
-    end
-  end
-
   let(:settings) do
     new_settings(provider_local)
   end
diff --git a/spec/components/site_settings/type_supervisor_spec.rb b/spec/components/site_settings/type_supervisor_spec.rb
index 9aa361c..9648b0e 100644
--- a/spec/components/site_settings/type_supervisor_spec.rb
+++ b/spec/components/site_settings/type_supervisor_spec.rb
@@ -6,13 +6,6 @@ describe SiteSettings::TypeSupervisor do
     SiteSettings::LocalProcessProvider.new
   end
 
-  def new_settings(provider)
-    Class.new do
-      extend SiteSettingExtension
-      self.provider = provider
-    end
-  end
-
   let :settings do
     new_settings(provider_local)
   end
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index 0d58507..a2e2202 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -70,6 +70,7 @@ RSpec.configure do |config|
   config.include MessageBus
   config.include RSpecHtmlMatchers
   config.include IntegrationHelpers, type: :request
+  config.include SiteSettingsHelpers
   config.mock_framework = :mocha
   config.order = 'random'
   config.infer_spec_type_from_file_location!
diff --git a/spec/support/site_settings_helpers.rb b/spec/support/site_settings_helpers.rb
new file mode 100644
index 0000000..5e196f8
--- /dev/null
+++ b/spec/support/site_settings_helpers.rb
@@ -0,0 +1,11 @@
+module SiteSettingsHelpers
+  def new_settings(provider)
+    Class.new do
+      extend SiteSettingExtension
+      # we want to avoid leaking a big pile of MessageBus subscriptions here (1 per class)
+      # so we set listen_for_changes to false
+      self.listen_for_changes = false
+      self.provider = provider
+    end
+  end
+end

GitHub sha: 51b19e94