From 1e3caeafa0daac408a5a9b6d1ca6eb051ede5404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Tue, 13 Aug 2024 16:30:54 +0200 Subject: [PATCH] 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. --- .../having_multiple_tagged_loggers_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 spec/integrity/having_multiple_tagged_loggers_spec.rb diff --git a/spec/integrity/having_multiple_tagged_loggers_spec.rb b/spec/integrity/having_multiple_tagged_loggers_spec.rb new file mode 100644 index 00000000000..c2c20dcbabc --- /dev/null +++ b/spec/integrity/having_multiple_tagged_loggers_spec.rb @@ -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