Welcome to mirror list, hosted at ThFree Co, Russian Federation.

locking_spec.rb « partitioning « gitlab_patches « active_record « spec « activerecord-gitlab « gems - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: df9241e0983e7b08ddd4314caf073e050c827a3a (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
# frozen_string_literal: true

RSpec.describe 'ActiveRecord::GitlabPatches::Partitioning::Associations::Locking', :partitioning do
  let!(:job) { LockingJob.create!(partition_id: 100) }

  describe 'optimistic locking' do
    it 'does not use lock version on unrelated updates' do
      update_statement = <<~SQL.squish
        UPDATE "locking_jobs" SET "name" = 'test'
        WHERE "locking_jobs"."id" = #{job.id} AND "locking_jobs"."partition_id" = #{job.partition_id}
      SQL

      result = QueryRecorder.log do
        job.update!(name: 'test')
      end

      expect(result).to include(update_statement)
    end

    it 'uses lock version when status changes' do
      update_statement = <<~SQL.squish
        UPDATE "locking_jobs"
        SET "status" = 1, "name" = 'test', "lock_version" = 1
        WHERE "locking_jobs"."id" = 1 AND "locking_jobs"."partition_id" = 100 AND "locking_jobs"."lock_version" = 0
      SQL

      result = QueryRecorder.log do
        job.update!(name: 'test', status: :completed)
      end

      expect(result).to include(update_statement)
    end
  end
end