From 60492caa98d7da6d1dd04710c9bc3f762bdceebd Mon Sep 17 00:00:00 2001
From: Grzegorz Bizon <grzesiek.bizon@gmail.com>
Date: Tue, 19 Apr 2016 12:47:34 +0200
Subject: [PATCH] Add tests exercising builds scheduler after cancel

---
 spec/models/ci/commit_spec.rb | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/spec/models/ci/commit_spec.rb b/spec/models/ci/commit_spec.rb
index 0bc7722ce6e..6055c142e21 100644
--- a/spec/models/ci/commit_spec.rb
+++ b/spec/models/ci/commit_spec.rb
@@ -258,6 +258,24 @@ describe Ci::Commit, models: true do
           expect(commit.status).to eq('failed')
         end
       end
+
+      context 'when build is canceled in the second stage' do
+        it 'does not schedule builds after build has been canceled' do
+          expect(create_builds).to be_truthy
+          expect(commit.builds.pluck(:name)).to contain_exactly('build')
+          expect(commit.builds.pluck(:status)).to contain_exactly('pending')
+          commit.builds.running_or_pending.each(&:success)
+
+          expect(commit.builds.running_or_pending).to_not be_empty
+
+          expect(commit.builds.pluck(:name)).to contain_exactly('build', 'test')
+          expect(commit.builds.pluck(:status)).to contain_exactly('success', 'pending')
+          commit.builds.running_or_pending.each(&:cancel)
+
+          expect(commit.builds.running_or_pending).to be_empty
+          expect(commit.reload.status).to eq('canceled')
+        end
+      end
     end
   end
 
-- 
GitLab