summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-17 09:07:07 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-17 09:07:07 +0000
commit4226aca420920c1844e8eade4798a2dff188a6fc (patch)
tree2a09417654e9617a13798d97ae32c495c66d3353 /spec
parent74b0522ed8b86edee204643c5484da1724a5a31b (diff)
downloadgitlab-ce-4226aca420920c1844e8eade4798a2dff188a6fc.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/graphql/mutations/concerns/mutations/resolves_project_spec.rb2
-rw-r--r--spec/graphql/mutations/merge_requests/set_wip_spec.rb2
-rw-r--r--spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb2
-rw-r--r--spec/graphql/resolvers/issues_resolver_spec.rb2
-rw-r--r--spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb2
-rw-r--r--spec/graphql/resolvers/merge_requests_resolver_spec.rb2
-rw-r--r--spec/graphql/resolvers/metadata_resolver_spec.rb2
-rw-r--r--spec/graphql/resolvers/project_pipelines_resolver_spec.rb2
-rw-r--r--spec/graphql/resolvers/project_resolver_spec.rb2
-rw-r--r--spec/graphql/resolvers/tree_resolver_spec.rb2
-rw-r--r--spec/graphql/types/ci/detailed_status_type_spec.rb2
-rw-r--r--spec/graphql/types/ci/pipeline_type_spec.rb2
-rw-r--r--spec/graphql/types/extended_issue_type_spec.rb2
-rw-r--r--spec/graphql/types/issue_type_spec.rb2
-rw-r--r--spec/graphql/types/merge_request_type_spec.rb2
-rw-r--r--spec/graphql/types/metadata_type_spec.rb2
-rw-r--r--spec/graphql/types/permission_types/base_permission_type_spec.rb2
-rw-r--r--spec/graphql/types/permission_types/issue_spec.rb2
-rw-r--r--spec/graphql/types/permission_types/merge_request_spec.rb2
-rw-r--r--spec/graphql/types/permission_types/merge_request_type_spec.rb2
-rw-r--r--spec/graphql/types/permission_types/note_spec.rb2
-rw-r--r--spec/graphql/types/permission_types/project_spec.rb2
-rw-r--r--spec/graphql/types/project_type_spec.rb2
-rw-r--r--spec/graphql/types/query_type_spec.rb2
-rw-r--r--spec/graphql/types/repository_type_spec.rb2
-rw-r--r--spec/graphql/types/time_type_spec.rb2
-rw-r--r--spec/lib/gitlab/sidekiq_daemon/memory_killer_spec.rb173
27 files changed, 187 insertions, 38 deletions
diff --git a/spec/graphql/mutations/concerns/mutations/resolves_project_spec.rb b/spec/graphql/mutations/concerns/mutations/resolves_project_spec.rb
index aa0f5c55902..09d1f66a2c7 100644
--- a/spec/graphql/mutations/concerns/mutations/resolves_project_spec.rb
+++ b/spec/graphql/mutations/concerns/mutations/resolves_project_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Mutations::ResolvesProject do
diff --git a/spec/graphql/mutations/merge_requests/set_wip_spec.rb b/spec/graphql/mutations/merge_requests/set_wip_spec.rb
index e600abf3941..c4accab9e46 100644
--- a/spec/graphql/mutations/merge_requests/set_wip_spec.rb
+++ b/spec/graphql/mutations/merge_requests/set_wip_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Mutations::MergeRequests::SetWip do
diff --git a/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb b/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb
index 3140af27af5..fa031af4013 100644
--- a/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb
+++ b/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe ResolvesPipelines do
diff --git a/spec/graphql/resolvers/issues_resolver_spec.rb b/spec/graphql/resolvers/issues_resolver_spec.rb
index d122c081069..2232c9b7d7b 100644
--- a/spec/graphql/resolvers/issues_resolver_spec.rb
+++ b/spec/graphql/resolvers/issues_resolver_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Resolvers::IssuesResolver do
diff --git a/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb b/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb
index 09b17bf6fc9..b8bdfc36ba7 100644
--- a/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb
+++ b/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Resolvers::MergeRequestPipelinesResolver do
diff --git a/spec/graphql/resolvers/merge_requests_resolver_spec.rb b/spec/graphql/resolvers/merge_requests_resolver_spec.rb
index 97b8e5ed41c..fe167a6ae3e 100644
--- a/spec/graphql/resolvers/merge_requests_resolver_spec.rb
+++ b/spec/graphql/resolvers/merge_requests_resolver_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Resolvers::MergeRequestsResolver do
diff --git a/spec/graphql/resolvers/metadata_resolver_spec.rb b/spec/graphql/resolvers/metadata_resolver_spec.rb
index e662ed127a5..afff9eabb97 100644
--- a/spec/graphql/resolvers/metadata_resolver_spec.rb
+++ b/spec/graphql/resolvers/metadata_resolver_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Resolvers::MetadataResolver do
diff --git a/spec/graphql/resolvers/project_pipelines_resolver_spec.rb b/spec/graphql/resolvers/project_pipelines_resolver_spec.rb
index 6862ae8a5ed..f312a118c96 100644
--- a/spec/graphql/resolvers/project_pipelines_resolver_spec.rb
+++ b/spec/graphql/resolvers/project_pipelines_resolver_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Resolvers::ProjectPipelinesResolver do
diff --git a/spec/graphql/resolvers/project_resolver_spec.rb b/spec/graphql/resolvers/project_resolver_spec.rb
index d0fc2957909..860f8b4abb8 100644
--- a/spec/graphql/resolvers/project_resolver_spec.rb
+++ b/spec/graphql/resolvers/project_resolver_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Resolvers::ProjectResolver do
diff --git a/spec/graphql/resolvers/tree_resolver_spec.rb b/spec/graphql/resolvers/tree_resolver_spec.rb
index 9f95b740ab1..0ea4e6eeaad 100644
--- a/spec/graphql/resolvers/tree_resolver_spec.rb
+++ b/spec/graphql/resolvers/tree_resolver_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Resolvers::TreeResolver do
diff --git a/spec/graphql/types/ci/detailed_status_type_spec.rb b/spec/graphql/types/ci/detailed_status_type_spec.rb
index a21162adb42..169a03c770b 100644
--- a/spec/graphql/types/ci/detailed_status_type_spec.rb
+++ b/spec/graphql/types/ci/detailed_status_type_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Types::Ci::DetailedStatusType do
diff --git a/spec/graphql/types/ci/pipeline_type_spec.rb b/spec/graphql/types/ci/pipeline_type_spec.rb
index ec1c689a4be..2fafc1bc13f 100644
--- a/spec/graphql/types/ci/pipeline_type_spec.rb
+++ b/spec/graphql/types/ci/pipeline_type_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Types::Ci::PipelineType do
diff --git a/spec/graphql/types/extended_issue_type_spec.rb b/spec/graphql/types/extended_issue_type_spec.rb
index 047f4a90d54..72ce53ae1be 100644
--- a/spec/graphql/types/extended_issue_type_spec.rb
+++ b/spec/graphql/types/extended_issue_type_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe GitlabSchema.types['ExtendedIssue'] do
diff --git a/spec/graphql/types/issue_type_spec.rb b/spec/graphql/types/issue_type_spec.rb
index 59c42aa446d..8aa2385ddaa 100644
--- a/spec/graphql/types/issue_type_spec.rb
+++ b/spec/graphql/types/issue_type_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe GitlabSchema.types['Issue'] do
diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb
index 59bd0123d88..6904c2dcd07 100644
--- a/spec/graphql/types/merge_request_type_spec.rb
+++ b/spec/graphql/types/merge_request_type_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe GitlabSchema.types['MergeRequest'] do
diff --git a/spec/graphql/types/metadata_type_spec.rb b/spec/graphql/types/metadata_type_spec.rb
index 5236380e477..2988f3c6ba5 100644
--- a/spec/graphql/types/metadata_type_spec.rb
+++ b/spec/graphql/types/metadata_type_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe GitlabSchema.types['Metadata'] do
diff --git a/spec/graphql/types/permission_types/base_permission_type_spec.rb b/spec/graphql/types/permission_types/base_permission_type_spec.rb
index 0ee8b883d51..a45102e5b50 100644
--- a/spec/graphql/types/permission_types/base_permission_type_spec.rb
+++ b/spec/graphql/types/permission_types/base_permission_type_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Types::PermissionTypes::BasePermissionType do
diff --git a/spec/graphql/types/permission_types/issue_spec.rb b/spec/graphql/types/permission_types/issue_spec.rb
index f0fbeda202f..a94bc6b780e 100644
--- a/spec/graphql/types/permission_types/issue_spec.rb
+++ b/spec/graphql/types/permission_types/issue_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Types::PermissionTypes::Issue do
diff --git a/spec/graphql/types/permission_types/merge_request_spec.rb b/spec/graphql/types/permission_types/merge_request_spec.rb
index e1026b01a74..e0f8bdd4712 100644
--- a/spec/graphql/types/permission_types/merge_request_spec.rb
+++ b/spec/graphql/types/permission_types/merge_request_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Types::PermissionTypes::MergeRequest do
diff --git a/spec/graphql/types/permission_types/merge_request_type_spec.rb b/spec/graphql/types/permission_types/merge_request_type_spec.rb
index 6e57122867a..572b4ac42d0 100644
--- a/spec/graphql/types/permission_types/merge_request_type_spec.rb
+++ b/spec/graphql/types/permission_types/merge_request_type_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Types::MergeRequestType do
diff --git a/spec/graphql/types/permission_types/note_spec.rb b/spec/graphql/types/permission_types/note_spec.rb
index 32d56eb1f7a..a7811fc20e5 100644
--- a/spec/graphql/types/permission_types/note_spec.rb
+++ b/spec/graphql/types/permission_types/note_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe GitlabSchema.types['NotePermissions'] do
diff --git a/spec/graphql/types/permission_types/project_spec.rb b/spec/graphql/types/permission_types/project_spec.rb
index 4974995b587..6d5a905c128 100644
--- a/spec/graphql/types/permission_types/project_spec.rb
+++ b/spec/graphql/types/permission_types/project_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Types::PermissionTypes::Project do
diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb
index 739e48044d1..f632b904e78 100644
--- a/spec/graphql/types/project_type_spec.rb
+++ b/spec/graphql/types/project_type_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe GitlabSchema.types['Project'] do
diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb
index bc3b8a42392..784a4f4b4c9 100644
--- a/spec/graphql/types/query_type_spec.rb
+++ b/spec/graphql/types/query_type_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe GitlabSchema.types['Query'] do
diff --git a/spec/graphql/types/repository_type_spec.rb b/spec/graphql/types/repository_type_spec.rb
index 8a8238f2a2a..236f9bb9459 100644
--- a/spec/graphql/types/repository_type_spec.rb
+++ b/spec/graphql/types/repository_type_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe GitlabSchema.types['Repository'] do
diff --git a/spec/graphql/types/time_type_spec.rb b/spec/graphql/types/time_type_spec.rb
index 4196d9d27d4..88a535ed3bb 100644
--- a/spec/graphql/types/time_type_spec.rb
+++ b/spec/graphql/types/time_type_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe GitlabSchema.types['Time'] do
diff --git a/spec/lib/gitlab/sidekiq_daemon/memory_killer_spec.rb b/spec/lib/gitlab/sidekiq_daemon/memory_killer_spec.rb
index adea2ba30b3..45bcc71dfcb 100644
--- a/spec/lib/gitlab/sidekiq_daemon/memory_killer_spec.rb
+++ b/spec/lib/gitlab/sidekiq_daemon/memory_killer_spec.rb
@@ -7,9 +7,12 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
let(:pid) { 12345 }
before do
- allow(memory_killer).to receive(:pid).and_return(pid)
allow(Sidekiq.logger).to receive(:info)
allow(Sidekiq.logger).to receive(:warn)
+ allow(memory_killer).to receive(:pid).and_return(pid)
+
+ # make sleep no-op
+ allow(memory_killer).to receive(:sleep) {}
end
describe '#run_thread' do
@@ -39,8 +42,9 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
pid: pid,
message: "Exception from run_thread: My Exception")
- expect(memory_killer).to receive(:rss_within_range?).twice.and_raise(StandardError, 'My Exception')
- expect(memory_killer).to receive(:sleep).twice.with(Gitlab::SidekiqDaemon::MemoryKiller::CHECK_INTERVAL_SECONDS)
+ expect(memory_killer).to receive(:rss_within_range?)
+ .twice
+ .and_raise(StandardError, 'My Exception')
expect { subject }.not_to raise_exception
end
@@ -52,7 +56,9 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
pid: pid,
message: "Exception from run_thread: My Exception")
- expect(memory_killer).to receive(:rss_within_range?).once.and_raise(Exception, 'My Exception')
+ expect(memory_killer).to receive(:rss_within_range?)
+ .once
+ .and_raise(Exception, 'My Exception')
expect(memory_killer).to receive(:sleep).with(Gitlab::SidekiqDaemon::MemoryKiller::CHECK_INTERVAL_SECONDS)
expect(Sidekiq.logger).to receive(:warn).once
@@ -78,7 +84,9 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
end
it 'not invoke restart_sidekiq when rss in range' do
- expect(memory_killer).to receive(:rss_within_range?).twice.and_return(true)
+ expect(memory_killer).to receive(:rss_within_range?)
+ .twice
+ .and_return(true)
expect(memory_killer).not_to receive(:restart_sidekiq)
@@ -86,9 +94,12 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
end
it 'invoke restart_sidekiq when rss not in range' do
- expect(memory_killer).to receive(:rss_within_range?).at_least(:once).and_return(false)
+ expect(memory_killer).to receive(:rss_within_range?)
+ .at_least(:once)
+ .and_return(false)
- expect(memory_killer).to receive(:restart_sidekiq).at_least(:once)
+ expect(memory_killer).to receive(:restart_sidekiq)
+ .at_least(:once)
subject
end
@@ -97,10 +108,9 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
describe '#stop_working' do
subject { memory_killer.send(:stop_working)}
- it 'changed enable? to false' do
- expect(memory_killer.send(:enabled?)).to be true
- subject
- expect(memory_killer.send(:enabled?)).to be false
+ it 'changes enable? to false' do
+ expect { subject }.to change { memory_killer.send(:enabled?) }
+ .from(true).to(false)
end
end
@@ -121,8 +131,12 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
it 'return true when everything is within limit' do
expect(memory_killer).to receive(:get_rss).and_return(100)
- expect(memory_killer).to receive(:soft_limit_rss).and_return(200)
- expect(memory_killer).to receive(:hard_limit_rss).and_return(300)
+ expect(memory_killer).to receive(:get_soft_limit_rss).and_return(200)
+ expect(memory_killer).to receive(:get_hard_limit_rss).and_return(300)
+
+ expect(memory_killer).to receive(:refresh_state)
+ .with(:running)
+ .and_call_original
expect(Gitlab::Metrics::System).to receive(:monotonic_time).and_call_original
expect(memory_killer).not_to receive(:log_rss_out_of_range)
@@ -131,9 +145,17 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
end
it 'return false when rss exceeds hard_limit_rss' do
- expect(memory_killer).to receive(:get_rss).and_return(400)
- expect(memory_killer).to receive(:soft_limit_rss).at_least(:once).and_return(200)
- expect(memory_killer).to receive(:hard_limit_rss).at_least(:once).and_return(300)
+ expect(memory_killer).to receive(:get_rss).at_least(:once).and_return(400)
+ expect(memory_killer).to receive(:get_soft_limit_rss).at_least(:once).and_return(200)
+ expect(memory_killer).to receive(:get_hard_limit_rss).at_least(:once).and_return(300)
+
+ expect(memory_killer).to receive(:refresh_state)
+ .with(:running)
+ .and_call_original
+
+ expect(memory_killer).to receive(:refresh_state)
+ .with(:above_soft_limit)
+ .and_call_original
expect(Gitlab::Metrics::System).to receive(:monotonic_time).and_call_original
@@ -143,13 +165,21 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
end
it 'return false when rss exceed hard_limit_rss after a while' do
- expect(memory_killer).to receive(:get_rss).and_return(250, 400)
- expect(memory_killer).to receive(:soft_limit_rss).at_least(:once).and_return(200)
- expect(memory_killer).to receive(:hard_limit_rss).at_least(:once).and_return(300)
+ expect(memory_killer).to receive(:get_rss).and_return(250, 400, 400)
+ expect(memory_killer).to receive(:get_soft_limit_rss).at_least(:once).and_return(200)
+ expect(memory_killer).to receive(:get_hard_limit_rss).at_least(:once).and_return(300)
+
+ expect(memory_killer).to receive(:refresh_state)
+ .with(:running)
+ .and_call_original
+
+ expect(memory_killer).to receive(:refresh_state)
+ .at_least(:once)
+ .with(:above_soft_limit)
+ .and_call_original
expect(Gitlab::Metrics::System).to receive(:monotonic_time).twice.and_call_original
expect(memory_killer).to receive(:sleep).with(check_interval_seconds)
-
expect(memory_killer).to receive(:log_rss_out_of_range).with(400, 300, 200)
expect(subject).to be false
@@ -157,8 +187,16 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
it 'return true when rss below soft_limit_rss after a while within GRACE_BALLOON_SECONDS' do
expect(memory_killer).to receive(:get_rss).and_return(250, 100)
- expect(memory_killer).to receive(:soft_limit_rss).and_return(200, 200)
- expect(memory_killer).to receive(:hard_limit_rss).and_return(300, 300)
+ expect(memory_killer).to receive(:get_soft_limit_rss).and_return(200, 200)
+ expect(memory_killer).to receive(:get_hard_limit_rss).and_return(300, 300)
+
+ expect(memory_killer).to receive(:refresh_state)
+ .with(:running)
+ .and_call_original
+
+ expect(memory_killer).to receive(:refresh_state)
+ .with(:above_soft_limit)
+ .and_call_original
expect(Gitlab::Metrics::System).to receive(:monotonic_time).twice.and_call_original
expect(memory_killer).to receive(:sleep).with(check_interval_seconds)
@@ -168,17 +206,27 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
expect(subject).to be true
end
- it 'return false when rss exceed soft_limit_rss longer than GRACE_BALLOON_SECONDS' do
- expect(memory_killer).to receive(:get_rss).exactly(4).times.and_return(250)
- expect(memory_killer).to receive(:soft_limit_rss).exactly(5).times.and_return(200)
- expect(memory_killer).to receive(:hard_limit_rss).exactly(5).times.and_return(300)
+ context 'when exceeding GRACE_BALLOON_SECONDS' do
+ let(:grace_balloon_seconds) { 0 }
- expect(Gitlab::Metrics::System).to receive(:monotonic_time).exactly(5).times.and_call_original
- expect(memory_killer).to receive(:sleep).exactly(3).times.with(check_interval_seconds).and_call_original
+ it 'return false when rss exceed soft_limit_rss' do
+ allow(memory_killer).to receive(:get_rss).and_return(250)
+ allow(memory_killer).to receive(:get_soft_limit_rss).and_return(200)
+ allow(memory_killer).to receive(:get_hard_limit_rss).and_return(300)
- expect(memory_killer).to receive(:log_rss_out_of_range).with(250, 300, 200)
+ expect(memory_killer).to receive(:refresh_state)
+ .with(:running)
+ .and_call_original
- expect(subject).to be false
+ expect(memory_killer).to receive(:refresh_state)
+ .with(:above_soft_limit)
+ .and_call_original
+
+ expect(memory_killer).to receive(:log_rss_out_of_range)
+ .with(250, 300, 200)
+
+ expect(subject).to be false
+ end
end
end
@@ -190,19 +238,42 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
before do
stub_const("#{described_class}::SHUTDOWN_TIMEOUT_SECONDS", shutdown_timeout_seconds)
allow(Sidekiq).to receive(:options).and_return(timeout: 9)
+ allow(memory_killer).to receive(:get_rss).and_return(100)
+ allow(memory_killer).to receive(:get_soft_limit_rss).and_return(200)
+ allow(memory_killer).to receive(:get_hard_limit_rss).and_return(300)
end
it 'send signal' do
- expect(memory_killer).to receive(:signal_and_wait).with(shutdown_timeout_seconds, 'SIGTSTP', 'stop fetching new jobs').ordered
- expect(memory_killer).to receive(:signal_and_wait).with(11, 'SIGTERM', 'gracefully shut down').ordered
- expect(memory_killer).to receive(:signal_pgroup).with('SIGKILL', 'die').ordered
+ expect(memory_killer).to receive(:refresh_state)
+ .with(:stop_fetching_new_jobs)
+ .ordered
+ .and_call_original
+ expect(memory_killer).to receive(:signal_and_wait)
+ .with(shutdown_timeout_seconds, 'SIGTSTP', 'stop fetching new jobs')
+ .ordered
+
+ expect(memory_killer).to receive(:refresh_state)
+ .with(:shutting_down)
+ .ordered
+ .and_call_original
+ expect(memory_killer).to receive(:signal_and_wait)
+ .with(11, 'SIGTERM', 'gracefully shut down')
+ .ordered
+
+ expect(memory_killer).to receive(:refresh_state)
+ .with(:killing_sidekiq)
+ .ordered
+ .and_call_original
+ expect(memory_killer).to receive(:signal_pgroup)
+ .with('SIGKILL', 'die')
+ .ordered
subject
end
end
describe '#signal_and_wait' do
- let(:time) { 7 }
+ let(:time) { 0 }
let(:signal) { 'my-signal' }
let(:explanation) { 'my-explanation' }
let(:check_interval_seconds) { 2 }
@@ -226,14 +297,17 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
end
it 'send signal and wait till deadline if any job not finished' do
- expect(Process).to receive(:kill).with(signal, pid).ordered
- expect(Gitlab::Metrics::System).to receive(:monotonic_time).and_call_original.at_least(:once)
+ expect(Process).to receive(:kill)
+ .with(signal, pid)
+ .ordered
+
+ expect(Gitlab::Metrics::System).to receive(:monotonic_time)
+ .and_call_original
+ .at_least(:once)
expect(memory_killer).to receive(:enabled?).and_return(true).at_least(:once)
expect(memory_killer).to receive(:any_jobs?).and_return(true).at_least(:once)
- expect(memory_killer).to receive(:sleep).and_call_original.exactly(4).times
-
subject
end
end
@@ -401,4 +475,27 @@ describe Gitlab::SidekiqDaemon::MemoryKiller do
expect(subject).to eq(10)
end
end
+
+ describe '#refresh_state' do
+ let(:metrics) { memory_killer.instance_variable_get(:@metrics) }
+
+ subject { memory_killer.send(:refresh_state, :shutting_down) }
+
+ it 'calls gitlab metrics gauge set methods' do
+ expect(memory_killer).to receive(:get_rss) { 1010 }
+ expect(memory_killer).to receive(:get_soft_limit_rss) { 1020 }
+ expect(memory_killer).to receive(:get_hard_limit_rss) { 1040 }
+
+ expect(metrics[:sidekiq_memory_killer_phase]).to receive(:set)
+ .with({}, described_class::PHASE[:shutting_down])
+ expect(metrics[:sidekiq_current_rss]).to receive(:set)
+ .with({}, 1010)
+ expect(metrics[:sidekiq_memory_killer_soft_limit_rss]).to receive(:set)
+ .with({}, 1020)
+ expect(metrics[:sidekiq_memory_killer_hard_limit_rss]).to receive(:set)
+ .with({}, 1040)
+
+ subject
+ end
+ end
end