From c949d95951e91de3565ce5eeaa06a9f35ef8d0b3 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 14 Oct 2024 15:24:29 +0800 Subject: [PATCH] DEV: Fix not flushing Redis properly for system test. (#29188) In ed6c9d154591b620e3347a417173b373f4738be7, we started flushing Redis's database at the end of each test. However, we had something like this: ``` config.after(:each, type: :system) { teardown system test stuff } config.after(:each) { # flush redis } ``` When stuff was defined in this order, flushing redis was called before the teardown of system test. Instead we have to switch the order around which is what this commit does. --- spec/rails_helper.rb | 54 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 72df165de21..805a4561c42 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -678,6 +678,33 @@ RSpec.configure do |config| BlockRequestsMiddleware.current_example_location = example.location end + config.after :each do |example| + if example.exception && RspecErrorTracker.exceptions.present? + lines = (RSpec.current_example.metadata[:extra_failure_lines] ||= +"") + + lines << "~~~~~~~ SERVER EXCEPTIONS ~~~~~~~" + + RspecErrorTracker.exceptions.each_with_index do |(path, ex), index| + lines << "\n" + lines << "Error encountered while proccessing #{path}" + lines << " #{ex.class}: #{ex.message}" + ex.backtrace.each_with_index do |line, backtrace_index| + if ENV["RSPEC_EXCLUDE_GEMS_IN_BACKTRACE"] + next if line.match?(%r{/gems/}) + end + lines << " #{line}\n" + end + end + + lines << "~~~~~~~ END SERVER EXCEPTIONS ~~~~~~~" + lines << "\n" + end + + unfreeze_time + ActionMailer::Base.deliveries.clear + Discourse.redis.flushdb + end + config.after(:each, type: :system) do |example| lines = RSpec.current_example.metadata[:extra_failure_lines] @@ -738,33 +765,6 @@ RSpec.configure do |config| MessageBus.backend_instance.reset! # Clears all existing backlog from memory backend end - config.after :each do |example| - if example.exception && RspecErrorTracker.exceptions.present? - lines = (RSpec.current_example.metadata[:extra_failure_lines] ||= +"") - - lines << "~~~~~~~ SERVER EXCEPTIONS ~~~~~~~" - - RspecErrorTracker.exceptions.each_with_index do |(path, ex), index| - lines << "\n" - lines << "Error encountered while proccessing #{path}" - lines << " #{ex.class}: #{ex.message}" - ex.backtrace.each_with_index do |line, backtrace_index| - if ENV["RSPEC_EXCLUDE_GEMS_IN_BACKTRACE"] - next if line.match?(%r{/gems/}) - end - lines << " #{line}\n" - end - end - - lines << "~~~~~~~ END SERVER EXCEPTIONS ~~~~~~~" - lines << "\n" - end - - unfreeze_time - ActionMailer::Base.deliveries.clear - Discourse.redis.flushdb - end - config.before(:each, type: :multisite) do Rails.configuration.multisite = true # rubocop:disable Discourse/NoDirectMultisiteManipulation