2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-05 11:46:34 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2020-03-20 23:18:34 +08:00
|
|
|
RSpec.describe "Redis rake tasks", type: :multisite do
|
2019-12-03 17:05:53 +08:00
|
|
|
let(:redis) { Discourse.redis.without_namespace }
|
2016-12-05 11:46:34 +08:00
|
|
|
|
|
|
|
before do
|
|
|
|
Discourse::Application.load_tasks
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'clean up' do
|
|
|
|
it 'should clean up orphan Redis keys' do
|
|
|
|
active_keys = [
|
|
|
|
'__mb_backlog_id_n_/users/someusername$|$default',
|
|
|
|
'default:user-last-seen:607',
|
|
|
|
'sidekiq:something:do:something',
|
|
|
|
'somekeytonotbetouched'
|
|
|
|
]
|
|
|
|
|
|
|
|
orphan_keys = [
|
|
|
|
'tgxworld:user-last-seen:607',
|
|
|
|
'__mb_backlog_id_n_/users/someusername$|$tgxworld'
|
|
|
|
]
|
|
|
|
|
|
|
|
(active_keys | orphan_keys).each do |key|
|
|
|
|
redis.set(key, 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
Rake::Task['redis:clean_up'].invoke
|
|
|
|
|
|
|
|
active_keys.each do |key|
|
|
|
|
expect(redis.get(key)).to eq('1')
|
|
|
|
end
|
|
|
|
|
|
|
|
orphan_keys.each do |key|
|
|
|
|
expect(redis.get(key)).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|