Skip to content

Commit

Permalink
Ensure Kredis.namespace is set in the thread that executes the test
Browse files Browse the repository at this point in the history
Otherwise, Kredis.namespace may be nil, resulting in wiping the whole Redis
db in test teardown.
  • Loading branch information
jeremy committed Dec 17, 2024
1 parent 57cedf5 commit 0350346
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/kredis/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ class Kredis::Railtie < ::Rails::Railtie

initializer "kredis.testing" do
ActiveSupport.on_load(:active_support_test_case) do
parallelize_setup { |worker| Kredis.namespace = "test-#{worker}" }
teardown { Kredis.clear_all }
$kredis_parallel_worker = nil
parallelize_setup { |worker| $kredis_parallel_worker = worker }

setup do
@original_namespace = Kredis.namespace
Kredis.namespace = [ @original_namespace, :test, $kredis_parallel_worker ].compact.join("-")
end

teardown do
Kredis.clear_all
Kredis.namespace = @original_namespace
end
end
end

Expand Down

0 comments on commit 0350346

Please sign in to comment.