diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-03-18 17:13:09 +0100 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2018-03-18 19:53:19 +0100 |
commit | c3b489bdcb1d6cf8bcdb935c73892dc5465eacbd (patch) | |
tree | 7acd01a9a3658755dddb3ab91323e8e37316b942 | |
parent | e7393191ee209beb1d39727384e4be21434415c6 (diff) | |
download | gitlab-ce-31114-internal-ids-are-not-atomic.tar.gz |
Add spec for concurrent insert situation.31114-internal-ids-are-not-atomic
-rw-r--r-- | spec/models/internal_id_spec.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/models/internal_id_spec.rb b/spec/models/internal_id_spec.rb index 40d777c46cc..581fd0293cc 100644 --- a/spec/models/internal_id_spec.rb +++ b/spec/models/internal_id_spec.rb @@ -38,6 +38,19 @@ describe InternalId do expect(subject).to eq(project.issues.size + 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] } + record = double + expect(described_class).to receive(:find_by).with(args).and_return(nil) # first call, record not present + expect(described_class).to receive(:find_by).with(args).and_return(record) # second call, record was created by another process + expect(described_class).to receive(:create!).and_raise(ActiveRecord::RecordNotUnique, 'record not unique') + expect(record).to receive(:increment_and_save!) + + subject + end + end end it 'generates a strictly monotone, gapless sequence' do |