summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git/storage/forked_storage_check_spec.rb
blob: 12366151f4457907c37cdbcdc9d2d6d8aae82672 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'spec_helper'

describe Gitlab::Git::Storage::ForkedStorageCheck, skip_database_cleaner: true do
  let(:existing_path) do
    existing_path = TestEnv.repos_path
    FileUtils.mkdir_p(existing_path)
    existing_path
  end

  describe '.storage_accessible?' do
    it 'detects when a storage is not available' do
      expect(described_class.storage_available?('/non/existant/path')).to be_falsey
    end

    it 'detects when a storage is available' do
      expect(described_class.storage_available?(existing_path)).to be_truthy
    end

    it 'returns false when the check takes to long' do
      # We're forking a process here that takes too long
      # It will be killed it's parent process will be killed by it's parent
      # and waited for inside `Gitlab::Git::Storage::ForkedStorageCheck.timeout_check`
      allow(described_class).to receive(:check_filesystem_in_process) do
        Process.spawn("sleep 10")
      end
      result = true

      runtime = Benchmark.realtime do
        result = described_class.storage_available?(existing_path, 0.5)
      end

      expect(result).to be_falsey
      expect(runtime).to be < 1.0
    end

    describe 'when using paths with spaces' do
      let(:test_dir) { Rails.root.join('tmp', 'tests', 'storage_check') }
      let(:path_with_spaces) { File.join(test_dir, 'path with spaces') }

      around do |example|
        FileUtils.mkdir_p(path_with_spaces)
        example.run
        FileUtils.rm_r(test_dir)
      end

      it 'works for paths with spaces' do
        expect(described_class.storage_available?(path_with_spaces)).to be_truthy
      end

      it 'works for a realpath with spaces' do
        symlink_location = File.join(test_dir, 'a symlink')
        FileUtils.ln_s(path_with_spaces, symlink_location)

        expect(described_class.storage_available?(symlink_location)).to be_truthy
      end
    end
  end
end