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:
Diffstat (limited to 'spec/lib/gitlab/memory/watchdog_spec.rb')
-rw-r--r--spec/lib/gitlab/memory/watchdog_spec.rb86
1 files changed, 17 insertions, 69 deletions
diff --git a/spec/lib/gitlab/memory/watchdog_spec.rb b/spec/lib/gitlab/memory/watchdog_spec.rb
index 0b2f24476d9..dd6bfb6da2c 100644
--- a/spec/lib/gitlab/memory/watchdog_spec.rb
+++ b/spec/lib/gitlab/memory/watchdog_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Memory::Watchdog, :aggregate_failures, feature_category: :application_performance do
context 'watchdog' do
let(:configuration) { instance_double(described_class::Configuration) }
- let(:handler) { instance_double(described_class::NullHandler) }
+ let(:handler) { instance_double(described_class::Handlers::NullHandler) }
let(:reporter) { instance_double(described_class::EventReporter) }
let(:sleep_time_seconds) { 60 }
let(:threshold_violated) { false }
@@ -60,10 +60,10 @@ RSpec.describe Gitlab::Memory::Watchdog, :aggregate_failures, feature_category:
it 'reports started event once' do
expect(reporter).to receive(:started).once
- .with(
+ .with({
memwd_handler_class: handler.class.name,
memwd_sleep_time_s: sleep_time_seconds
- )
+ })
watchdog.call
end
@@ -77,11 +77,11 @@ RSpec.describe Gitlab::Memory::Watchdog, :aggregate_failures, feature_category:
context 'when no monitors are configured' do
it 'reports stopped event once with correct reason' do
expect(reporter).to receive(:stopped).once
- .with(
+ .with({
memwd_handler_class: handler.class.name,
memwd_sleep_time_s: sleep_time_seconds,
memwd_reason: 'monitors are not configured'
- )
+ })
watchdog.call
end
@@ -96,11 +96,11 @@ RSpec.describe Gitlab::Memory::Watchdog, :aggregate_failures, feature_category:
it 'reports stopped event once' do
expect(reporter).to receive(:stopped).once
- .with(
+ .with({
memwd_handler_class: handler.class.name,
memwd_sleep_time_s: sleep_time_seconds,
memwd_reason: 'background task stopped'
- )
+ })
watchdog.call
end
@@ -149,13 +149,13 @@ RSpec.describe Gitlab::Memory::Watchdog, :aggregate_failures, feature_category:
it 'reports strikes exceeded event' do
expect(reporter).to receive(:strikes_exceeded)
.with(
- name,
- memwd_handler_class: handler.class.name,
- memwd_sleep_time_s: sleep_time_seconds,
- memwd_cur_strikes: 1,
- memwd_max_strikes: max_strikes,
- message: "dummy_text"
- )
+ name, {
+ memwd_handler_class: handler.class.name,
+ memwd_sleep_time_s: sleep_time_seconds,
+ memwd_cur_strikes: 1,
+ memwd_max_strikes: max_strikes,
+ message: "dummy_text"
+ })
watchdog.call
end
@@ -163,11 +163,11 @@ RSpec.describe Gitlab::Memory::Watchdog, :aggregate_failures, feature_category:
it 'executes handler and stops the watchdog' do
expect(handler).to receive(:call).and_return(true)
expect(reporter).to receive(:stopped).once
- .with(
+ .with({
memwd_handler_class: handler.class.name,
memwd_sleep_time_s: sleep_time_seconds,
memwd_reason: 'successfully handled'
- )
+ })
watchdog.call
end
@@ -185,7 +185,7 @@ RSpec.describe Gitlab::Memory::Watchdog, :aggregate_failures, feature_category:
it 'always uses the NullHandler' do
expect(handler).not_to receive(:call)
- expect(described_class::NullHandler.instance).to receive(:call).and_return(true)
+ expect(described_class::Handlers::NullHandler.instance).to receive(:call).and_return(true)
watchdog.call
end
@@ -216,56 +216,4 @@ RSpec.describe Gitlab::Memory::Watchdog, :aggregate_failures, feature_category:
end
end
end
-
- context 'handlers' do
- context 'NullHandler' do
- subject(:handler) { described_class::NullHandler.instance }
-
- describe '#call' do
- it 'does nothing' do
- expect(handler.call).to be(false)
- end
- end
- end
-
- context 'TermProcessHandler' do
- subject(:handler) { described_class::TermProcessHandler.new(42) }
-
- describe '#call' do
- before do
- allow(Process).to receive(:kill)
- end
-
- it 'sends SIGTERM to the current process' do
- expect(Process).to receive(:kill).with(:TERM, 42)
-
- expect(handler.call).to be(true)
- end
- end
- end
-
- context 'PumaHandler' do
- # rubocop: disable RSpec/VerifiedDoubles
- # In tests, the Puma constant is not loaded so we cannot make this an instance_double.
- let(:puma_worker_handle_class) { double('Puma::Cluster::WorkerHandle') }
- let(:puma_worker_handle) { double('worker') }
- # rubocop: enable RSpec/VerifiedDoubles
-
- subject(:handler) { described_class::PumaHandler.new({}) }
-
- before do
- stub_const('::Puma::Cluster::WorkerHandle', puma_worker_handle_class)
- allow(puma_worker_handle_class).to receive(:new).and_return(puma_worker_handle)
- allow(puma_worker_handle).to receive(:term)
- end
-
- describe '#call' do
- it 'invokes orderly termination via Puma API' do
- expect(puma_worker_handle).to receive(:term)
-
- expect(handler.call).to be(true)
- end
- end
- end
- end
end