summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-03-29 11:36:26 +0000
committerJames Lopez <james@jameslopez.es>2017-04-03 12:11:57 +0200
commit54842848ec3bd520874c7d88ffc7d30e43e312d4 (patch)
tree8df0ec30095ce6032d51f2de889a421a85f249b1
parent3e59fd2d9746e1ec666e1ea1228b47bba1c40f24 (diff)
downloadgitlab-ce-54842848ec3bd520874c7d88ffc7d30e43e312d4.tar.gz
Merge branch 'optimistic-locking-ci-status-change' into 'master'
Make CI build to use optimistic locking only on status change Closes #29679 See merge request !10152
-rw-r--r--app/models/commit_status.rb4
-rw-r--r--changelogs/unreleased/make-ci-build-to-lock-on-status-change.yml4
-rw-r--r--spec/models/commit_status_spec.rb36
3 files changed, 44 insertions, 0 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index 8c71267da65..17b322b5ae3 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -105,6 +105,10 @@ class CommitStatus < ActiveRecord::Base
end
end
+ def locking_enabled?
+ status_changed?
+ end
+
def before_sha
pipeline.before_sha || Gitlab::Git::BLANK_SHA
end
diff --git a/changelogs/unreleased/make-ci-build-to-lock-on-status-change.yml b/changelogs/unreleased/make-ci-build-to-lock-on-status-change.yml
new file mode 100644
index 00000000000..b0c5eb4ed17
--- /dev/null
+++ b/changelogs/unreleased/make-ci-build-to-lock-on-status-change.yml
@@ -0,0 +1,4 @@
+---
+title: Make CI build to use optimistic locking only on status change
+merge_request:
+author:
diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb
index ea5e4e21039..7343b735a74 100644
--- a/spec/models/commit_status_spec.rb
+++ b/spec/models/commit_status_spec.rb
@@ -297,4 +297,40 @@ describe CommitStatus, :models do
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