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
path: root/spec
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-04-16 18:22:40 +0300
committerFilipa Lacerda <filipa@gitlab.com>2018-04-17 15:31:42 +0300
commit365e45fd8b90a058cd35725fbae01b82fd1d9a49 (patch)
treef45ddc4eb7d82977dc4315bbe6a1a47eb372bdb4 /spec
parent9422e56313434869b179159d44cae7186e50fe3d (diff)
Merge branch '45269-double-checked-internal-ids' into 'master'
Double-checked internal ID generation for transition phase Closes #45269 See merge request gitlab-org/gitlab-ce!18392
Diffstat (limited to 'spec')
-rw-r--r--spec/models/internal_id_spec.rb37
1 files changed, 35 insertions, 2 deletions
diff --git a/spec/models/internal_id_spec.rb b/spec/models/internal_id_spec.rb
index 581fd0293cc..8ef91e8fab5 100644
--- a/spec/models/internal_id_spec.rb
+++ b/spec/models/internal_id_spec.rb
@@ -5,7 +5,7 @@ describe InternalId do
let(:usage) { :issues }
let(:issue) { build(:issue, project: project) }
let(:scope) { { project: project } }
- let(:init) { ->(s) { s.project.issues.size } }
+ let(:init) { ->(s) { s.project.issues.maximum(:iid) } }
context 'validations' do
it { is_expected.to validate_presence_of(:usage) }
@@ -39,6 +39,29 @@ describe InternalId do
end
end
+ context 'with an InternalId record present and existing issues with a higher internal id' do
+ # This can happen if the old NonatomicInternalId is still in use
+ before do
+ issues = Array.new(rand(1..10)).map { create(:issue, project: project) }
+
+ issue = issues.last
+ issue.iid = issues.map { |i| i.iid }.max + 1
+ issue.save
+ end
+
+ let(:maximum_iid) { project.issues.map { |i| i.iid }.max }
+
+ it 'updates last_value to the maximum internal id present' do
+ subject
+
+ expect(described_class.find_by(project: project, usage: described_class.usages[usage.to_s]).last_value).to eq(maximum_iid + 1)
+ end
+
+ it 'returns next internal id correctly' do
+ expect(subject).to eq(maximum_iid + 1)
+ end
+ end
+
context 'with concurrent inserts on table' do
it 'looks up the record if it was created concurrently' do
args = { **scope, usage: described_class.usages[usage.to_s] }
@@ -81,7 +104,8 @@ describe InternalId do
describe '#increment_and_save!' do
let(:id) { create(:internal_id) }
- subject { id.increment_and_save! }
+ let(:maximum_iid) { nil }
+ subject { id.increment_and_save!(maximum_iid) }
it 'returns incremented iid' do
value = id.last_value
@@ -102,5 +126,14 @@ describe InternalId do
expect(subject).to eq(1)
end
end
+
+ context 'with maximum_iid given' do
+ let(:id) { create(:internal_id, last_value: 1) }
+ let(:maximum_iid) { id.last_value + 10 }
+
+ it 'returns maximum_iid instead' do
+ expect(subject).to eq(12)
+ end
+ end
end
end