discourse/spec/tasks/redis_spec.rb
David Taylor c9dab6fd08
DEV: Automatically require 'rails_helper' in all specs (#16077)
It's very easy to forget to add `require 'rails_helper'` at the top of every core/plugin spec file, and omissions can cause some very confusing/sporadic errors.

By setting this flag in `.rspec`, we can remove the need for `require 'rails_helper'` entirely.
2022-03-01 17:50:50 +00:00

42 lines
972 B
Ruby

# frozen_string_literal: true
RSpec.describe "Redis rake tasks", type: :multisite do
let(:redis) { Discourse.redis.without_namespace }
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
ensure
active_keys.each { |key| redis.del(key) }
end
end
end