Skip to content
Snippets Groups Projects

Broadcast message stale cache on different Gitlab revisions

All threads resolved!
Compare and Show latest version
3 files
+ 63
21
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -16,26 +16,30 @@
@@ -16,26 +16,30 @@
described_class.new(namespace: namespace, backend: backend, cache_key_strategy: cache_key_strategy)
described_class.new(namespace: namespace, backend: backend, cache_key_strategy: cache_key_strategy)
end
end
describe '#read' do
describe '#expire' do
context 'when the cached value is a hash' do
context 'with cache_key concerns' do
it 'parses the cached value' do
subject(:expire) { cache.expire(key) }
allow(backend).to receive(:read).with(expanded_key).and_return(json_value(broadcast_message))
expect(cache.read(key, BroadcastMessage)).to eq(broadcast_message)
it 'uses the expanded_key' do
end
expect(backend).to receive(:delete).with(expanded_key)
it 'returns nil when klass is nil' do
expire
allow(backend).to receive(:read).with(expanded_key).and_return(json_value(broadcast_message))
expect(cache.read(key)).to be_nil
end
end
it 'returns nil when the data has true value' do
context 'when namespace is nil' do
allow(backend).to receive(:read).with(expanded_key).and_return('_true_')
let(:namespace) { nil }
expect(cache.read(key)).to be_nil
it 'uses the expanded_key' do
 
expect(backend).to receive(:delete).with(key)
 
 
expire
 
end
end
end
 
end
 
end
 
describe '#read' do
 
context 'when the cached value is a hash' do
it 'returns nil when the data is not in a nested structure' do
it 'returns nil when the data is not in a nested structure' do
allow(backend).to receive(:read).with(expanded_key).and_return(%w[a b].to_json)
allow(backend).to receive(:read).with(expanded_key).and_return(%w[a b].to_json)
@@ -51,15 +55,19 @@
@@ -51,15 +55,19 @@
end
end
end
end
end
end
end
describe '#write' do
context 'when cache_key_strategy is unknown' do
it 'writes a string containing a JSON representation of the value to the cache' do
let(:cache_key_strategy) { 'unknown' }
cache.write(key, broadcast_message)
expect(backend).to have_received(:write).with(expanded_key, json_value(broadcast_message), nil)
it 'raises KeyError' do
 
allow(backend).to receive(:read).with(expanded_key).and_return(json_value(true))
 
 
expect { cache.read(key) }.to raise_error(KeyError)
 
end
end
end
 
end
 
describe '#write' do
context 'when there is an existing value in the cache' do
context 'when there is an existing value in the cache' do
it 'preserves the existing value when writing a different key' do
it 'preserves the existing value when writing a different key' do
current_cache = { '_other_revision_' => broadcast_message }
current_cache = { '_other_revision_' => broadcast_message }
Loading