diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-25 20:53:42 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-25 21:59:57 +0200 |
commit | a0497a7bc0726dfc7bc1b0f5568f0353436e128b (patch) | |
tree | 93ec6c042d62b5ba4f4a6fc3afabcef5197b0c31 /spec/lib/gitlab/health_checks | |
parent | 8067efdf3dab2b8f7e3893a49248243958948dfb (diff) | |
download | gitlab-ce-a0497a7bc0726dfc7bc1b0f5568f0353436e128b.tar.gz |
Move helpers to spec file, use const's instead of helper methods
Diffstat (limited to 'spec/lib/gitlab/health_checks')
-rw-r--r-- | spec/lib/gitlab/health_checks/fs_shards_check_spec.rb | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb b/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb index 1f0cfc1dcf6..61c10d47434 100644 --- a/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb +++ b/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb @@ -1,7 +1,23 @@ require 'spec_helper' describe Gitlab::HealthChecks::FsShardsCheck do - include TimeoutHelper + def command_exists?(command) + _, status = Gitlab::Popen.popen(%W{ #{command} 1 echo }) + status == 0 + rescue Errno::ENOENT + false + end + + def timeout_command + @timeout_command ||= + if command_exists?('timeout') + 'timeout' + elsif command_exists?('gtimeout') + 'gtimeout' + else + '' + end + end let(:metric_class) { Gitlab::HealthChecks::Metric } let(:result_class) { Gitlab::HealthChecks::Result } @@ -17,6 +33,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do before do allow(described_class).to receive(:repository_storages) { repository_storages } allow(described_class).to receive(:storages_paths) { storages_paths } + stub_const('Gitlab::HealthChecks::FsShardsCheck::TIMEOUT_EXECUTABLE', timeout_command) end after do @@ -109,10 +126,10 @@ describe Gitlab::HealthChecks::FsShardsCheck do end context 'when timeout kills fs checks' do - let(:timeout_seconds) { 1.to_s } - before do - allow(described_class).to receive(:with_timeout) { [timeout_command, timeout_seconds, 'sleep', '20'] } + stub_const('Gitlab::HealthChecks::FsShardsCheck::COMMAND_TIMEOUT', '1') + + allow(described_class).to receive(:exec_with_timeout).and_wrap_original { |m| m.call(%w(sleep 60)) } FileUtils.chmod_R(0755, tmp_dir) end @@ -140,7 +157,6 @@ describe Gitlab::HealthChecks::FsShardsCheck do end context 'when popen always finds required binaries' do - let(:timeout_seconds) { 30.to_s } before do allow(described_class).to receive(:exec_with_timeout).and_wrap_original do |method, *args, &block| begin @@ -150,9 +166,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do end end - allow(described_class).to receive(:with_timeout) do |args, &block| - [timeout_command, timeout_seconds].concat(args) - end + stub_const('Gitlab::HealthChecks::FsShardsCheck::COMMAND_TIMEOUT', '10') end it_behaves_like 'filesystem checks' |