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:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-11 00:15:20 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-11 00:15:20 +0300
commit9abffa14d6395d56b77313541d63e0c12ae2b602 (patch)
tree55eb69304c835d5e0b49344d331ee851add9647a /spec/metrics_server
parente0277d5393d958865fdec470176ac5874edded06 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/metrics_server')
-rw-r--r--spec/metrics_server/metrics_server_spec.rb71
1 files changed, 44 insertions, 27 deletions
diff --git a/spec/metrics_server/metrics_server_spec.rb b/spec/metrics_server/metrics_server_spec.rb
index fc18df9b5cd..c90fd162814 100644
--- a/spec/metrics_server/metrics_server_spec.rb
+++ b/spec/metrics_server/metrics_server_spec.rb
@@ -15,9 +15,16 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
# we need to reset it after testing.
let!(:old_multiprocess_files_dir) { prometheus_config.multiprocess_files_dir }
+ let(:ruby_sampler_double) { double(Gitlab::Metrics::Samplers::RubySampler) }
+
before do
# We do not want this to have knock-on effects on the test process.
allow(Gitlab::ProcessManagement).to receive(:modify_signals)
+
+ # This being a singleton, we stub it out because only one instance is allowed
+ # to exist per process.
+ allow(Gitlab::Metrics::Samplers::RubySampler).to receive(:initialize_instance).and_return(ruby_sampler_double)
+ allow(ruby_sampler_double).to receive(:start)
end
after do
@@ -27,35 +34,49 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
FileUtils.rm_rf(metrics_dir, secure: true)
end
- describe '.spawn' do
- context 'when in parent process' do
- it 'forks into a new process and detaches it' do
- expect(Process).to receive(:fork).and_return(99)
- expect(Process).to receive(:detach).with(99)
+ %w(puma sidekiq).each do |target|
+ context "when targeting #{target}" do
+ describe '.spawn' do
+ context 'when in parent process' do
+ it 'forks into a new process and detaches it' do
+ expect(Process).to receive(:fork).and_return(99)
+ expect(Process).to receive(:detach).with(99)
- described_class.spawn('sidekiq', metrics_dir: metrics_dir)
- end
- end
+ described_class.spawn(target, metrics_dir: metrics_dir)
+ end
+ end
- context 'when in child process' do
- before do
- # This signals the process that it's "inside" the fork
- expect(Process).to receive(:fork).and_return(nil)
- expect(Process).not_to receive(:detach)
- end
+ context 'when in child process' do
+ before do
+ # This signals the process that it's "inside" the fork
+ expect(Process).to receive(:fork).and_return(nil)
+ expect(Process).not_to receive(:detach)
+ end
- it 'starts the metrics server with the given arguments' do
- expect_next_instance_of(MetricsServer) do |server|
- expect(server).to receive(:start)
- end
+ it 'starts the metrics server with the given arguments' do
+ expect_next_instance_of(MetricsServer) do |server|
+ expect(server).to receive(:start)
+ end
- described_class.spawn('sidekiq', metrics_dir: metrics_dir)
- end
+ described_class.spawn(target, metrics_dir: metrics_dir)
+ end
- it 'resets signal handlers from parent process' do
- expect(Gitlab::ProcessManagement).to receive(:modify_signals).with(%i[A B], 'DEFAULT')
+ it 'resets signal handlers from parent process' do
+ expect(Gitlab::ProcessManagement).to receive(:modify_signals).with(%i[A B], 'DEFAULT')
- described_class.spawn('sidekiq', metrics_dir: metrics_dir, trapped_signals: %i[A B])
+ described_class.spawn(target, metrics_dir: metrics_dir, trapped_signals: %i[A B])
+ end
+ end
+ end
+ end
+ end
+
+ context 'when targeting invalid target' do
+ describe '.spawn' do
+ it 'raises an error' do
+ expect { described_class.spawn('unsupported', metrics_dir: metrics_dir) }.to(
+ raise_error('Target must be one of [puma,sidekiq]')
+ )
end
end
end
@@ -64,7 +85,6 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
let(:exporter_class) { Class.new(Gitlab::Metrics::Exporter::BaseExporter) }
let(:exporter_double) { double('fake_exporter', start: true) }
let(:settings) { { "fake_exporter" => { "enabled" => true } } }
- let(:ruby_sampler_double) { double(Gitlab::Metrics::Samplers::RubySampler) }
subject(:metrics_server) { described_class.new('fake', metrics_dir, true)}
@@ -74,9 +94,6 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
settings['fake_exporter'], gc_requests: true, synchronous: true
).and_return(exporter_double)
expect(Settings).to receive(:monitoring).and_return(settings)
-
- allow(Gitlab::Metrics::Samplers::RubySampler).to receive(:initialize_instance).and_return(ruby_sampler_double)
- allow(ruby_sampler_double).to receive(:start)
end
it 'configures ::Prometheus::Client' do