From 89ba0344221adec516d2f14da237b1097bb34825 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Mon, 13 Jan 2025 17:03:56 +1100 Subject: [PATCH] DEV: Improve distributed cache multisite specs (#30662) Distributed cache when namespace is false is not multisite safe as values are shared between sites. Distributed cache with namespace option (default) is multisite safe. Improved specs to cover both cases. --- spec/multisite/distributed_cache_spec.rb | 28 +++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/spec/multisite/distributed_cache_spec.rb b/spec/multisite/distributed_cache_spec.rb index 0fed72dee8d..f269c748352 100644 --- a/spec/multisite/distributed_cache_spec.rb +++ b/spec/multisite/distributed_cache_spec.rb @@ -8,7 +8,7 @@ RSpec.describe "Multisite SiteSettings", type: :multisite do context "without namespace" do let(:cache1) { cache("test", namespace: false) } - it "does not leak state across multisite" do + it "does share a global state between multisite" do cache1["default"] = true expect(cache1.hash).to eq("default" => true) @@ -23,9 +23,35 @@ RSpec.describe "Multisite SiteSettings", type: :multisite do expect(message.data[:op]).to eq(:set) expect(message.data[:key]).to eq("second") expect(message.data[:value]).to eq(true) + expect(cache1.hash).to eq("default" => true, "second" => true) end expect(cache1.hash).to eq("default" => true, "second" => true) end end + + context "with namespace" do + let(:cache1) { cache("test", namespace: true) } + + it "does not share a state between multisite" do + cache1["default"] = true + + expect(cache1.hash).to eq("default" => true) + + test_multisite_connection("second") do + message = + MessageBus + .track_publish(DistributedCache::Manager::CHANNEL_NAME) { cache1["second"] = true } + .first + + expect(message.data[:hash_key]).to eq("test") + expect(message.data[:op]).to eq(:set) + expect(message.data[:key]).to eq("second") + expect(message.data[:value]).to eq(true) + expect(cache1.hash).to eq("second" => true) + end + + expect(cache1.hash).to eq("default" => true) + end + end end