mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 08:51:05 +08:00
Fix Redis command errors when trying to start app with a readonly Redis.
This commit is contained in:
@ -10,6 +10,70 @@ describe DiscourseRedis do
|
||||
|
||||
let(:fallback_handler) { DiscourseRedis::FallbackHandler.instance }
|
||||
|
||||
describe 'redis commands' do
|
||||
let(:raw_redis) { Redis.new(DiscourseRedis.config) }
|
||||
|
||||
before do
|
||||
raw_redis.flushall
|
||||
end
|
||||
|
||||
after do
|
||||
raw_redis.flushall
|
||||
end
|
||||
|
||||
describe 'when namespace is enabled' do
|
||||
let(:redis) { DiscourseRedis.new }
|
||||
|
||||
it 'should append namespace to the keys' do
|
||||
redis.set('key', 1)
|
||||
|
||||
expect(raw_redis.get('default:key')).to eq('1')
|
||||
expect(redis.keys).to eq(['key'])
|
||||
|
||||
redis.del('key')
|
||||
|
||||
expect(raw_redis.get('default:key')).to eq(nil)
|
||||
|
||||
raw_redis.set('default:key1', '1')
|
||||
raw_redis.set('default:key2', '2')
|
||||
|
||||
expect(redis.mget('key1', 'key2')).to eq(['1', '2'])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when namespace is disabled' do
|
||||
let(:redis) { DiscourseRedis.new(nil, namespace: false) }
|
||||
|
||||
it 'should not append any namespace to the keys' do
|
||||
redis.set('key', 1)
|
||||
|
||||
expect(raw_redis.get('key')).to eq('1')
|
||||
expect(redis.keys).to eq(['key'])
|
||||
|
||||
redis.del('key')
|
||||
|
||||
expect(raw_redis.get('key')).to eq(nil)
|
||||
|
||||
raw_redis.set('key1', '1')
|
||||
raw_redis.set('key2', '2')
|
||||
|
||||
expect(redis.mget('key1', 'key2')).to eq(['1', '2'])
|
||||
end
|
||||
|
||||
it 'should noop a readonly redis' do
|
||||
expect(Discourse.recently_readonly?).to eq(false)
|
||||
|
||||
redis.without_namespace
|
||||
.expects(:set)
|
||||
.raises(Redis::CommandError.new("READONLY"))
|
||||
|
||||
redis.set('key', 1)
|
||||
|
||||
expect(Discourse.recently_readonly?).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context '.slave_host' do
|
||||
it 'should return the right config' do
|
||||
slave_config = DiscourseRedis.slave_config(config)
|
||||
@ -22,9 +86,9 @@ describe DiscourseRedis do
|
||||
it 'should check the status of the master server' do
|
||||
begin
|
||||
fallback_handler.master = false
|
||||
$redis.without_namespace.expects(:get).raises(Redis::CommandError.new("READONLY"))
|
||||
$redis.without_namespace.expects(:set).raises(Redis::CommandError.new("READONLY"))
|
||||
fallback_handler.expects(:verify_master).once
|
||||
$redis.get('test')
|
||||
$redis.set('test', '1')
|
||||
ensure
|
||||
fallback_handler.master = true
|
||||
end
|
||||
|
Reference in New Issue
Block a user