DEV: Fix not flushing Redis properly for system test. (#29188)

In  ed6c9d1545, 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.
This commit is contained in:
Alan Guo Xiang Tan 2024-10-14 15:24:29 +08:00 committed by GitHub
parent bb5a58a686
commit c949d95951
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 27 deletions

View File

@ -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