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