summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-08-12 13:57:58 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2016-08-12 13:57:58 +0200
commitea4ac578534d3a233c3525bf8351eb2045f6e632 (patch)
treed4c96a160a7281c3ea1492f38f2d2c2e123e57f1
parentd7b681512bb738b9b2ca0c56e761616a1a761295 (diff)
downloadgitlab-ce-ea4ac578534d3a233c3525bf8351eb2045f6e632.tar.gz
Use event `enqueue` instead of `queue`
-rw-r--r--app/models/ci/build.rb4
-rw-r--r--app/models/ci/pipeline.rb20
-rw-r--r--app/models/commit_status.rb2
-rw-r--r--app/services/ci/process_pipeline_service.rb2
-rw-r--r--spec/models/build_spec.rb6
-rw-r--r--spec/models/ci/pipeline_spec.rb23
6 files changed, 34 insertions, 23 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 92dad9377c9..3d6c6ea3209 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -59,7 +59,7 @@ module Ci
when: build.when,
user: user,
environment: build.environment,
- status_event: 'queue'
+ status_event: 'enqueue'
)
MergeRequests::AddTodoWhenBuildFailsService.new(build.project, nil).close(new_build)
new_build
@@ -102,7 +102,7 @@ module Ci
def play(current_user = nil)
# Try to queue a current build
- if self.queue
+ if self.enqueue
self.update(user: current_user)
self
else
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 6820b2d41a7..d00de56bf07 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -20,7 +20,7 @@ module Ci
after_save :keep_around_commits
state_machine :status, initial: :created do
- event :queue do
+ event :enqueue do
transition created: :pending
transition any - [:created, :pending] => :running
end
@@ -224,18 +224,12 @@ module Ci
def build_updated
case latest_builds_status
- when 'pending'
- queue
- when 'running'
- run
- when 'success'
- succeed
- when 'failed'
- drop
- when 'canceled'
- cancel
- when 'skipped'
- skip
+ when 'pending' then enqueue
+ when 'running' then run
+ when 'success' then succeed
+ when 'failed' then drop
+ when 'canceled' then cancel
+ when 'skipped' then skip
end
end
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index c21c8ce18db..703ca90edb6 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -26,7 +26,7 @@ class CommitStatus < ActiveRecord::Base
scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) }
state_machine :status do
- event :queue do
+ event :enqueue do
transition [:created, :skipped] => :pending
end
diff --git a/app/services/ci/process_pipeline_service.rb b/app/services/ci/process_pipeline_service.rb
index 86c4823d18a..6f7610d42ba 100644
--- a/app/services/ci/process_pipeline_service.rb
+++ b/app/services/ci/process_pipeline_service.rb
@@ -37,7 +37,7 @@ module Ci
return false unless Statuseable::COMPLETED_STATUSES.include?(current_status)
if valid_statuses_for_when(build.when).include?(current_status)
- build.queue
+ build.enqueue
true
else
build.skip
diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb
index 60a221eba50..04fb074cfd8 100644
--- a/spec/models/build_spec.rb
+++ b/spec/models/build_spec.rb
@@ -886,8 +886,10 @@ describe Ci::Build, models: true do
is_expected.to eq(build)
end
- context 'for success build' do
- before { build.queue }
+ context 'for successful build' do
+ before do
+ build.success
+ end
it 'creates a new build' do
is_expected.to be_pending
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 28d07f67b26..950833cb219 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -143,7 +143,7 @@ describe Ci::Pipeline, models: true do
expect(pipeline.reload.started_at).not_to be_nil
end
- it 'do not update on transitioning to success' do
+ it 'does not update on transitioning to success' do
build.success
expect(pipeline.reload.started_at).to be_nil
@@ -157,7 +157,7 @@ describe Ci::Pipeline, models: true do
expect(pipeline.reload.finished_at).not_to be_nil
end
- it 'do not update on transitioning to running' do
+ it 'does not update on transitioning to running' do
build.run
expect(pipeline.reload.finished_at).to be_nil
@@ -257,14 +257,16 @@ describe Ci::Pipeline, models: true do
subject { pipeline.reload.status }
context 'on queuing' do
- before { build.queue }
+ before do
+ build.enqueue
+ end
it { is_expected.to eq('pending') }
end
context 'on run' do
before do
- build.queue
+ build.enqueue
build.run
end
@@ -294,5 +296,18 @@ describe Ci::Pipeline, models: true do
it { is_expected.to eq('canceled') }
end
+
+ context 'on failure and build retry' do
+ before do
+ build.drop
+ Ci::Build.retry(build)
+ end
+
+ # We are changing a state: created > failed > running
+ # Instead of: created > failed > pending
+ # Since the pipeline already run, so it should not be pending anymore
+
+ it { is_expected.to eq('running') }
+ end
end
end