Commit e500cc49 authored by Stan Hu's avatar Stan Hu

Fix order-dependent Prometheus metrics specs

https://gitlab.com/gitlab-org/gitlab/merge_requests/22355 modified a
class instance variable, causing the error state to be enabled for all
subsequent tests. This commit fixes that by clearing the errors after
the tests run.

Closes https://gitlab.com/gitlab-org/gitlab/issues/196048
parent a2a8c590
...@@ -62,10 +62,18 @@ module Gitlab ...@@ -62,10 +62,18 @@ module Gitlab
end end
def error_detected! def error_detected!
set_error!(true)
end
def clear_errors!
set_error!(false)
end
def set_error!(status)
clear_memoization(:prometheus_metrics_enabled) clear_memoization(:prometheus_metrics_enabled)
PROVIDER_MUTEX.synchronize do PROVIDER_MUTEX.synchronize do
@error = true @error = status
end end
end end
......
...@@ -6,6 +6,10 @@ describe Gitlab::Metrics::Prometheus, :prometheus do ...@@ -6,6 +6,10 @@ describe Gitlab::Metrics::Prometheus, :prometheus do
let(:all_metrics) { Gitlab::Metrics } let(:all_metrics) { Gitlab::Metrics }
let(:registry) { all_metrics.registry } let(:registry) { all_metrics.registry }
after do
all_metrics.clear_errors!
end
describe '#reset_registry!' do describe '#reset_registry!' do
it 'clears existing metrics' do it 'clears existing metrics' do
registry.counter(:test, 'test metric') registry.counter(:test, 'test metric')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment