Make CI build to use optimistic locking only on status change
This commit is contained in:
		
							parent
							
								
									d70f9c8563
								
							
						
					
					
						commit
						bb910c3b46
					
				| 
						 | 
					@ -105,6 +105,10 @@ class CommitStatus < ActiveRecord::Base
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def locking_enabled?
 | 
				
			||||||
 | 
					    status_changed?
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def before_sha
 | 
					  def before_sha
 | 
				
			||||||
    pipeline.before_sha || Gitlab::Git::BLANK_SHA
 | 
					    pipeline.before_sha || Gitlab::Git::BLANK_SHA
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					title: Make CI build to use optimistic locking only on status change
 | 
				
			||||||
 | 
					merge_request:
 | 
				
			||||||
 | 
					author:
 | 
				
			||||||
| 
						 | 
					@ -297,4 +297,40 @@ describe CommitStatus, :models do
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  describe '#locking_enabled?' do
 | 
				
			||||||
 | 
					    before do
 | 
				
			||||||
 | 
					      commit_status.lock_version = 100
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    subject { commit_status.locking_enabled? }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    context "when changing status" do
 | 
				
			||||||
 | 
					      before do
 | 
				
			||||||
 | 
					        commit_status.status = "running"
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it "lock" do
 | 
				
			||||||
 | 
					        is_expected.to be true
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it "raise exception when trying to update" do
 | 
				
			||||||
 | 
					        expect{ commit_status.save }.to raise_error(ActiveRecord::StaleObjectError)
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    context "when changing description" do
 | 
				
			||||||
 | 
					      before do
 | 
				
			||||||
 | 
					        commit_status.description = "test"
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it "do not lock" do
 | 
				
			||||||
 | 
					        is_expected.to be false
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it "save correctly" do
 | 
				
			||||||
 | 
					        expect(commit_status.save).to be true
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue