debian-mirror-gitlab/spec/support/helpers/reactive_caching_helpers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.7 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module ReactiveCachingHelpers
def reactive_cache_key(subject, *qualifiers)
([subject.class.reactive_cache_key.call(subject)].flatten + qualifiers).join(':')
end
def alive_reactive_cache_key(subject, *qualifiers)
reactive_cache_key(subject, *(qualifiers + ['alive']))
end
def stub_reactive_cache(subject = nil, data = nil, *qualifiers)
2020-05-24 23:13:21 +05:30
ReactiveCaching::WORK_TYPE.values.each do |worker|
allow(worker).to receive(:perform_async)
allow(worker).to receive(:perform_in)
end
2019-09-30 21:07:59 +05:30
write_reactive_cache(subject, data, *qualifiers) unless subject.nil?
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
def synchronous_reactive_cache(subject)
2018-11-18 11:00:15 +05:30
allow(subject).to receive(:with_reactive_cache) do |*args, &block|
block.call(subject.calculate_reactive_cache(*args))
2018-03-17 18:26:18 +05:30
end
end
2017-08-17 22:00:37 +05:30
def read_reactive_cache(subject, *qualifiers)
Rails.cache.read(reactive_cache_key(subject, *qualifiers))
end
def write_reactive_cache(subject, data, *qualifiers)
start_reactive_cache_lifetime(subject, *qualifiers)
Rails.cache.write(reactive_cache_key(subject, *qualifiers), data)
end
def reactive_cache_alive?(subject, *qualifiers)
Rails.cache.read(alive_reactive_cache_key(subject, *qualifiers))
end
def invalidate_reactive_cache(subject, *qualifiers)
Rails.cache.delete(alive_reactive_cache_key(subject, *qualifiers))
end
def start_reactive_cache_lifetime(subject, *qualifiers)
Rails.cache.write(alive_reactive_cache_key(subject, *qualifiers), true)
end
2020-05-24 23:13:21 +05:30
def expect_reactive_cache_update_queued(subject, worker_klass: ReactiveCachingWorker)
expect(worker_klass)
2017-09-10 17:25:29 +05:30
.to receive(:perform_in)
.with(subject.class.reactive_cache_refresh_interval, subject.class, subject.id)
2017-08-17 22:00:37 +05:30
end
end