DEV: Add spec to ensure app works with multiple tagged loggers

When upgrading to Rails 7.1, we had some problems because we were using
several tagged loggers at the same time. They were all added to the main
broadcast logger shipped with Rails, but the Rails 7.1 codebase contains
a bug making a request being run as many times as there are tagged loggers.

The fix was to use the code from the Rails 7.2 codebase.

This patch adds a small spec to ensure the behavior will stay the proper
one in the future.
This commit is contained in:
Loïc Guitaut 2024-08-13 16:30:54 +02:00 committed by Loïc Guitaut
parent 31ae81b8eb
commit 1e3caeafa0

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
RSpec.describe "Having multiple tagged loggers", type: :request do
let(:loggers) { 2.times.map { ActiveSupport::TaggedLogging.new(Logger.new(nil)) } }
before { loggers.each { Rails.logger.broadcast_to(_1) } }
after { loggers.each { Rails.logger.stop_broadcasting_to(_1) } }
it "does not execute request twice" do
expect_any_instance_of(SilenceLogger).to receive(:call_app).once.and_call_original
get "/user_actions.json"
end
end