Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2016-12-17 07:09:50 +0300
committerNick Thomas <nick@gitlab.com>2016-12-19 22:53:03 +0300
commit5378302763e1a461bab5213aa379d5b9e6dc322c (patch)
tree121784b1e71ceee292bbfa06c4df3d88fc8f48c5 /spec/support/reactive_caching_helpers.rb
parent7c2e16d05319fa79d0b84472130c4a9300e08808 (diff)
Add a ReactiveCaching concern for use in the KubernetesService
Diffstat (limited to 'spec/support/reactive_caching_helpers.rb')
-rw-r--r--spec/support/reactive_caching_helpers.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/support/reactive_caching_helpers.rb b/spec/support/reactive_caching_helpers.rb
new file mode 100644
index 00000000000..279db3c5748
--- /dev/null
+++ b/spec/support/reactive_caching_helpers.rb
@@ -0,0 +1,38 @@
+module ReactiveCachingHelpers
+ def reactive_cache_key(subject, *qualifiers)
+ ([subject.class.reactive_cache_key.call(subject)].flatten + qualifiers).join(':')
+ end
+
+ def stub_reactive_cache(subject = nil, data = nil)
+ allow(ReactiveCachingWorker).to receive(:perform_async)
+ allow(ReactiveCachingWorker).to receive(:perform_in)
+ write_reactive_cache(subject, data) if data
+ end
+
+ def read_reactive_cache(subject)
+ Rails.cache.read(reactive_cache_key(subject))
+ end
+
+ def write_reactive_cache(subject, data)
+ start_reactive_cache_lifetime(subject)
+ Rails.cache.write(reactive_cache_key(subject), data)
+ end
+
+ def reactive_cache_alive?(subject)
+ Rails.cache.read(reactive_cache_key(subject, 'alive'))
+ end
+
+ def invalidate_reactive_cache(subject)
+ Rails.cache.delete(reactive_cache_key(subject, 'alive'))
+ end
+
+ def start_reactive_cache_lifetime(subject)
+ Rails.cache.write(reactive_cache_key(subject, 'alive'), true)
+ end
+
+ def expect_reactive_cache_update_queued(subject)
+ expect(ReactiveCachingWorker).
+ to receive(:perform_in).
+ with(subject.class.reactive_cache_refresh_interval, subject.class, subject.id)
+ end
+end