From 5fa52b4b2c7f918045310db34590e788c429c66c Mon Sep 17 00:00:00 2001 From: Nikita Shilnikov Date: Wed, 6 Mar 2024 14:34:56 +0100 Subject: [PATCH] Fix specs by checking if AS properly isolates global state --- .../active_support/tagged_logging.rb | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/dry/effects/extensions/active_support/tagged_logging.rb b/lib/dry/effects/extensions/active_support/tagged_logging.rb index 718efda..9276c9c 100644 --- a/lib/dry/effects/extensions/active_support/tagged_logging.rb +++ b/lib/dry/effects/extensions/active_support/tagged_logging.rb @@ -2,12 +2,18 @@ require "active_support/tagged_logging" -ActiveSupport::TaggedLogging::Formatter.prepend(Module.new { - def current_tags - thread_key = @thread_key ||= "activesupport_tagged_logging_tags:#{object_id}" - unless Thread.current.thread_variable_get(thread_key) - Thread.current.thread_variable_set(thread_key, []) +begin + require "active_support/isolated_execution_state" + + # it's not needed when state is already isolated +rescue LoadError + ActiveSupport::TaggedLogging::Formatter.prepend(Module.new { + def current_tags + thread_key = @thread_key ||= "activesupport_tagged_logging_tags:#{object_id}" + unless Thread.current.thread_variable_get(thread_key) + Thread.current.thread_variable_set(thread_key, []) + end + Thread.current.thread_variable_get(thread_key) end - Thread.current.thread_variable_get(thread_key) - end -}) + }) +end