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.
This commit is contained in:
Krzysztof Kotlarek 2025-01-13 17:03:56 +11:00 committed by GitHub
parent e8aa2b8d9a
commit 89ba034422
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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