From 7954d34448e74883a42e73274b07e386d2f2b04e Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Thu, 10 Aug 2023 07:32:27 +0800 Subject: [PATCH] DEV: Clean up more state in between system tests (#23009) Why this change? By default in the test environment, MessageBus used the memory backend which means all messages are stored in an in-memory data structure. However, the in-memory data structure is not cleared after each system test so we have the potential to be leaking stuff between system tests. Similarly for the defer queue which process work in another thread, we want to ensure that the defer queue processes everything it has to do before the transaction is rolled back. --- spec/rails_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index ea0057ef5ac..cca613f33f9 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -509,6 +509,8 @@ RSpec.configure do |config| end page.execute_script("if (typeof MessageBus !== 'undefined') { MessageBus.stop(); }") + MessageBus.backend_instance.reset! # Clears all existing backlog from memory backend + Scheduler::Defer.do_all_work # Process everything that was added to the defer queue when running the test Capybara.reset_sessions! Capybara.use_default_driver Discourse.redis.flushdb