2022-02-17 08:52:14 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-08 09:05:41 -05:00
|
|
|
RSpec.describe DistributedCache do
|
2023-01-09 05:18:21 -06:00
|
|
|
let(:cache) { described_class.new("mytest") }
|
2022-02-17 08:52:14 -06:00
|
|
|
|
|
|
|
it "can defer_get_set" do
|
2023-01-09 05:18:21 -06:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish("/distributed_hash") { cache.defer_get_set("key") { "value" } }
|
2022-02-17 08:52:14 -06:00
|
|
|
expect(messages.size).to eq(1)
|
|
|
|
expect(cache["key"]).to eq("value")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works correctly for nil values" do
|
|
|
|
block_called_counter = 0
|
2023-01-09 05:18:21 -06:00
|
|
|
messages =
|
|
|
|
MessageBus.track_publish("/distributed_hash") do
|
|
|
|
2.times do
|
|
|
|
cache.defer_get_set("key") do
|
|
|
|
block_called_counter += 1
|
|
|
|
nil
|
|
|
|
end
|
2022-02-17 08:52:14 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(block_called_counter).to eq(1)
|
|
|
|
expect(messages.size).to eq(1)
|
|
|
|
expect(cache["key"]).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|