diff options
author | Nick Thomas <nick@gitlab.com> | 2018-10-19 13:17:50 +0100 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-11-05 01:30:04 +0000 |
commit | f760c1cd17881c8aef3a33a3b43db54673db8111 (patch) | |
tree | e1ed99cee3bd9bce1b60f2487d967e8187b110c2 /spec/models/shard_spec.rb | |
parent | 93846eb152f32e149ef8c24b707fa0a0c0c52714 (diff) | |
download | gitlab-ce-f760c1cd17881c8aef3a33a3b43db54673db8111.tar.gz |
Start tracking shards in the database
Diffstat (limited to 'spec/models/shard_spec.rb')
-rw-r--r-- | spec/models/shard_spec.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/models/shard_spec.rb b/spec/models/shard_spec.rb new file mode 100644 index 00000000000..83104711b55 --- /dev/null +++ b/spec/models/shard_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literals: true +require 'spec_helper' + +describe Shard do + describe '.populate!' do + it 'creates shards based on the config file' do + expect(described_class.all).to be_empty + + stub_storage_settings(foo: {}, bar: {}, baz: {}) + + described_class.populate! + + expect(described_class.all.map(&:name)).to match_array(%w[default foo bar baz]) + end + end + + describe '.by_name' do + let(:default_shard) { described_class.find_by(name: 'default') } + + before do + described_class.populate! + end + + it 'returns an existing shard' do + expect(described_class.by_name('default')).to eq(default_shard) + end + + it 'creates a new shard' do + result = described_class.by_name('foo') + + expect(result).not_to eq(default_shard) + expect(result.name).to eq('foo') + end + + it 'retries if creation races' do + expect(described_class) + .to receive(:find_or_create_by) + .with(name: 'default') + .and_raise(ActiveRecord::RecordNotUnique, 'fail') + .once + + expect(described_class) + .to receive(:find_or_create_by) + .with(name: 'default') + .and_call_original + + expect(described_class.by_name('default')).to eq(default_shard) + end + end +end |