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