From b114bcd2949fee2925eab8faf34cd02d64eb3ab1 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Wed, 29 May 2019 16:34:55 +1000 Subject: [PATCH] DEV: switch message bus backend to memory for tests This backend is a bit faster and well tested, this is part of a longer term plan to have a `backend: :memory, threaded: false` type config for message bus which we can use in test. The threading in message bus causes all sorts of surprises in test, it will be nice not to be beholden to them. --- config/initializers/004-message_bus.rb | 7 +++++-- spec/requests/static_controller_spec.rb | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/config/initializers/004-message_bus.rb b/config/initializers/004-message_bus.rb index 57253d63b44..ac560c54003 100644 --- a/config/initializers/004-message_bus.rb +++ b/config/initializers/004-message_bus.rb @@ -94,8 +94,11 @@ MessageBus.on_disconnect do |site_id| ActiveRecord::Base.connection_handler.clear_active_connections! end -# Point at our redis -MessageBus.redis_config = GlobalSetting.message_bus_redis_config +if Rails.env == "test" + MessageBus.configure(backend: :memory) +else + MessageBus.redis_config = GlobalSetting.message_bus_redis_config +end MessageBus.reliable_pub_sub.max_backlog_size = GlobalSetting.message_bus_max_backlog_size MessageBus.long_polling_enabled = SiteSetting.enable_long_polling diff --git a/spec/requests/static_controller_spec.rb b/spec/requests/static_controller_spec.rb index 6c542a1e828..5553328c788 100644 --- a/spec/requests/static_controller_spec.rb +++ b/spec/requests/static_controller_spec.rb @@ -13,6 +13,10 @@ describe StaticController do UploadCreator.new(file, filename).create_for(Discourse.system_user.id) end + before_all do + DistributedMemoizer.flush! + end + after do DistributedMemoizer.flush! end