summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-12-11 23:39:40 +0100
committerPawel Chojnacki <pawel@chojnacki.ws>2017-12-12 18:38:28 +0100
commit408208bc2b75d28235092e9bb3821242fdad08fb (patch)
tree6efb1b69e76bed83caa2dba82050da31fdbd79d3 /spec/lib
parent5904b033dba553636ae2a06cbf1469d8f19df040 (diff)
downloadgitlab-ce-408208bc2b75d28235092e9bb3821242fdad08fb.tar.gz
Use AtomicFixNum to implement CAS isolated cache update.
i.e. Using compare and swap we update the expires_at value. The thread that actually is able to update this value will also set the cache holding method_call enabled state
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/metrics/method_call_spec.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/spec/lib/gitlab/metrics/method_call_spec.rb b/spec/lib/gitlab/metrics/method_call_spec.rb
index eca6a2cb54a..5ce62504245 100644
--- a/spec/lib/gitlab/metrics/method_call_spec.rb
+++ b/spec/lib/gitlab/metrics/method_call_spec.rb
@@ -21,7 +21,7 @@ describe Gitlab::Metrics::MethodCall do
context 'prometheus instrumentation is enabled' do
before do
allow(Feature.get(:prometheus_metrics_method_instrumentation)).to receive(:enabled?).and_call_original
- described_class::MEASUREMENT_ENABLED_CACHE.set({enabled: false, expires_at: Time.now - 1.second})
+ described_class::MEASUREMENT_ENABLED_CACHE_EXPIRES_AT.value = Time.now.to_i - 1
Feature.get(:prometheus_metrics_method_instrumentation).enable
end
@@ -39,12 +39,16 @@ describe Gitlab::Metrics::MethodCall do
expect(Feature.get(:prometheus_metrics_method_instrumentation)).to have_received(:enabled?).once
end
- it 'expires feature check cache after 5 minutes' do
+ it 'expires feature check cache after 30 seconds' do
10.times do
method_call.measure { 'foo' }
end
- Timecop.travel(Time.now + 5.minutes) do
+ Timecop.travel(Time.now + 30.seconds) do
+ method_call.measure { 'foo' }
+ end
+
+ Timecop.travel(Time.now + 31.seconds) do
method_call.measure { 'foo' }
end
@@ -62,7 +66,8 @@ describe Gitlab::Metrics::MethodCall do
context 'prometheus instrumentation is disabled' do
before do
- described_class::MEASUREMENT_ENABLED_CACHE.set({enabled: false, expires_at: Time.now})
+ described_class::MEASUREMENT_ENABLED_CACHE_EXPIRES_AT.value = Time.now.to_i - 1
+
Feature.get(:prometheus_metrics_method_instrumentation).disable
end