mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 10:54:22 +08:00
4ea21fa2d0
This change both speeds up specs (less strings to allocate) and helps catch cases where methods in Discourse are mutating inputs. Overall we will be migrating everything to use #frozen_string_literal: true it will take a while, but this is the first and safest move in this direction
48 lines
1.0 KiB
Ruby
48 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe "Redis rake tasks" do
|
|
let(:redis) { $redis.without_namespace }
|
|
|
|
before do
|
|
@multisite = Rails.configuration.multisite
|
|
Rails.configuration.multisite = true
|
|
Discourse::Application.load_tasks
|
|
end
|
|
|
|
after do
|
|
Rails.configuration.multisite = @multisite
|
|
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
|