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-11-07 18:11:00 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-11-07 18:11:00 +0300
commitfa4473a48706d074217f4ffc8d183cf630af1833 (patch)
tree6e2ae917c1351d24d0b5b65a86fd9da3cddb8bab /spec/initializers/memory_watchdog_spec.rb
parent1dab074ef1740798bcba5f8468b09e5f378fe0f4 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/initializers/memory_watchdog_spec.rb')
-rw-r--r--spec/initializers/memory_watchdog_spec.rb73
1 files changed, 4 insertions, 69 deletions
diff --git a/spec/initializers/memory_watchdog_spec.rb b/spec/initializers/memory_watchdog_spec.rb
index 36f96131c3d..5c3d020016a 100644
--- a/spec/initializers/memory_watchdog_spec.rb
+++ b/spec/initializers/memory_watchdog_spec.rb
@@ -29,28 +29,10 @@ RSpec.describe 'memory watchdog' do
run_initializer
end
- shared_examples 'starts configured watchdog' do |handler_class|
- let(:configuration) { Gitlab::Memory::Watchdog::Configuration.new }
- let(:watchdog_monitors_params) do
- {
- Gitlab::Memory::Watchdog::Monitor::HeapFragmentation => {
- max_heap_fragmentation: max_heap_fragmentation,
- max_strikes: max_strikes
- },
- Gitlab::Memory::Watchdog::Monitor::UniqueMemoryGrowth => {
- max_mem_growth: max_mem_growth,
- max_strikes: max_strikes
- }
- }
- end
-
+ shared_examples 'starts configured watchdog' do |configure_monitor_method|
shared_examples 'configures and starts watchdog' do
it "correctly configures and starts watchdog", :aggregate_failures do
- expect(watchdog).to receive(:configure).and_yield(configuration)
-
- watchdog_monitors_params.each do |monitor_class, params|
- expect(configuration.monitors).to receive(:use).with(monitor_class, **params)
- end
+ expect(Gitlab::Memory::Watchdog::Configurator).to receive(configure_monitor_method)
expect(Gitlab::Memory::Watchdog).to receive(:new).and_return(watchdog)
expect(Gitlab::BackgroundTask).to receive(:new).with(watchdog).and_return(background_task)
@@ -58,71 +40,24 @@ RSpec.describe 'memory watchdog' do
expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_start).and_yield
run_initializer
-
- expect(configuration.handler).to be_an_instance_of(handler_class)
- expect(configuration.logger).to eq(logger)
- expect(configuration.sleep_time_seconds).to eq(sleep_time_seconds)
end
end
-
- context 'when settings are not passed through the environment' do
- let(:max_strikes) { 5 }
- let(:max_heap_fragmentation) { 0.5 }
- let(:max_mem_growth) { 3.0 }
- let(:sleep_time_seconds) { 60 }
-
- include_examples 'configures and starts watchdog'
- end
-
- context 'when settings are passed through the environment' do
- let(:max_strikes) { 6 }
- let(:max_heap_fragmentation) { 0.4 }
- let(:max_mem_growth) { 2.0 }
- let(:sleep_time_seconds) { 50 }
-
- before do
- stub_env('GITLAB_MEMWD_MAX_STRIKES', 6)
- stub_env('GITLAB_MEMWD_SLEEP_TIME_SEC', 50)
- stub_env('GITLAB_MEMWD_MAX_MEM_GROWTH', 2.0)
- stub_env('GITLAB_MEMWD_MAX_HEAP_FRAG', 0.4)
- end
-
- include_examples 'configures and starts watchdog'
- end
end
- # In tests, the Puma constant does not exist so we cannot use a verified double.
- # rubocop: disable RSpec/VerifiedDoubles
context 'when puma' do
- let(:puma) do
- Class.new do
- def self.cli_config
- Struct.new(:options).new
- end
- end
- end
-
before do
- stub_const('Puma', puma)
- stub_const('Puma::Cluster::WorkerHandle', double.as_null_object)
-
allow(Gitlab::Runtime).to receive(:puma?).and_return(true)
end
- it_behaves_like 'starts configured watchdog', Gitlab::Memory::Watchdog::PumaHandler
+ it_behaves_like 'starts configured watchdog', :configure_for_puma
end
- # rubocop: enable RSpec/VerifiedDoubles
context 'when sidekiq' do
before do
allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true)
end
- it_behaves_like 'starts configured watchdog', Gitlab::Memory::Watchdog::TermProcessHandler
- end
-
- context 'when other runtime' do
- it_behaves_like 'starts configured watchdog', Gitlab::Memory::Watchdog::NullHandler
+ it_behaves_like 'starts configured watchdog', :configure_for_sidekiq
end
end