Commit 0332a8f9 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'master' of https://gitlab.com/gitlab-org/gitlab-ce into...

Merge branch 'master' of https://gitlab.com/gitlab-org/gitlab-ce into 2451-fix-mentions-in-issue-updates
parents 59bfa080 11eefba8
image: "ruby:2.3" image: "ruby:2.3.1"
cache: cache:
key: "ruby-23" key: "ruby-231"
paths: paths:
- vendor/apt - vendor/apt
- vendor/ruby - vendor/ruby
......
...@@ -25,6 +25,7 @@ v 8.11.0 (unreleased) ...@@ -25,6 +25,7 @@ v 8.11.0 (unreleased)
- Pre-create all builds for a Pipeline when the new Pipeline is created !5295 - Pre-create all builds for a Pipeline when the new Pipeline is created !5295
- Fix of 'Commits being passed to custom hooks are already reachable when using the UI' - Fix of 'Commits being passed to custom hooks are already reachable when using the UI'
- Show member roles to all users on members page - Show member roles to all users on members page
- Project.visible_to_user is instrumented again
- Fix awardable button mutuality loading spinners (ClemMakesApps) - Fix awardable button mutuality loading spinners (ClemMakesApps)
- Add support for using RequestStore within Sidekiq tasks via SIDEKIQ_REQUEST_STORE env variable - Add support for using RequestStore within Sidekiq tasks via SIDEKIQ_REQUEST_STORE env variable
- Optimize maximum user access level lookup in loading of notes - Optimize maximum user access level lookup in loading of notes
...@@ -92,6 +93,7 @@ v 8.11.0 (unreleased) ...@@ -92,6 +93,7 @@ v 8.11.0 (unreleased)
- Bump gitlab_git to lazy load compare commits - Bump gitlab_git to lazy load compare commits
- Reduce number of queries made for merge_requests/:id/diffs - Reduce number of queries made for merge_requests/:id/diffs
- Sensible state specific default sort order for issues and merge requests !5453 (tomb0y) - Sensible state specific default sort order for issues and merge requests !5453 (tomb0y)
- Fix bug where destroying a namespace would not always destroy projects
- Fix RequestProfiler::Middleware error when code is reloaded in development - Fix RequestProfiler::Middleware error when code is reloaded in development
- Catch what warden might throw when profiling requests to re-throw it - Catch what warden might throw when profiling requests to re-throw it
- Avoid commit lookup on diff_helper passing existing local variable to the helper method - Avoid commit lookup on diff_helper passing existing local variable to the helper method
......
.environments { .environments {
.commit-title { .commit-title {
margin: 0; margin: 0;
} }
.fa-play {
font-size: 14px;
}
.dropdown-new {
color: $table-text-gray;
}
.dropdown-menu {
.fa {
margin-right: 6px;
color: $table-text-gray;
}
}
.branch-name {
color: $gl-dark-link-color;
}
}
.table.builds.environments {
min-width: 500px;
.icon-container {
width: 20px;
text-align: center;
}
} }
...@@ -48,9 +48,9 @@ class Admin::GroupsController < Admin::ApplicationController ...@@ -48,9 +48,9 @@ class Admin::GroupsController < Admin::ApplicationController
end end
def destroy def destroy
DestroyGroupService.new(@group, current_user).execute DestroyGroupService.new(@group, current_user).async_execute
redirect_to admin_groups_path, notice: 'Group was successfully deleted.' redirect_to admin_groups_path, alert: "Group '#{@group.name}' was scheduled for deletion."
end end
private private
......
...@@ -87,9 +87,9 @@ class GroupsController < Groups::ApplicationController ...@@ -87,9 +87,9 @@ class GroupsController < Groups::ApplicationController
end end
def destroy def destroy
DestroyGroupService.new(@group, current_user).execute DestroyGroupService.new(@group, current_user).async_execute
redirect_to root_path, alert: "Group '#{@group.name}' was successfully deleted." redirect_to root_path, alert: "Group '#{@group.name}' was scheduled for deletion."
end end
protected protected
......
...@@ -7,8 +7,6 @@ module AvatarsHelper ...@@ -7,8 +7,6 @@ module AvatarsHelper
})) }))
end end
private
def user_avatar(options = {}) def user_avatar(options = {})
avatar_size = options[:size] || 16 avatar_size = options[:size] || 16
user_name = options[:user].try(:name) || options[:user_name] user_name = options[:user].try(:name) || options[:user_name]
......
...@@ -42,24 +42,25 @@ module Ci ...@@ -42,24 +42,25 @@ module Ci
end end
def retry(build, user = nil) def retry(build, user = nil)
new_build = Ci::Build.new(status: 'pending') new_build = Ci::Build.create(
new_build.ref = build.ref ref: build.ref,
new_build.tag = build.tag tag: build.tag,
new_build.options = build.options options: build.options,
new_build.commands = build.commands commands: build.commands,
new_build.tag_list = build.tag_list tag_list: build.tag_list,
new_build.project = build.project project: build.project,
new_build.pipeline = build.pipeline pipeline: build.pipeline,
new_build.name = build.name name: build.name,
new_build.allow_failure = build.allow_failure allow_failure: build.allow_failure,
new_build.stage = build.stage stage: build.stage,
new_build.stage_idx = build.stage_idx stage_idx: build.stage_idx,
new_build.trigger_request = build.trigger_request trigger_request: build.trigger_request,
new_build.yaml_variables = build.yaml_variables yaml_variables: build.yaml_variables,
new_build.when = build.when when: build.when,
new_build.user = user user: user,
new_build.environment = build.environment environment: build.environment,
new_build.save status_event: 'enqueue'
)
MergeRequests::AddTodoWhenBuildFailsService.new(build.project, nil).close(new_build) MergeRequests::AddTodoWhenBuildFailsService.new(build.project, nil).close(new_build)
new_build new_build
end end
...@@ -101,7 +102,7 @@ module Ci ...@@ -101,7 +102,7 @@ module Ci
def play(current_user = nil) def play(current_user = nil)
# Try to queue a current build # Try to queue a current build
if self.queue if self.enqueue
self.update(user: current_user) self.update(user: current_user)
self self
else else
......
...@@ -19,6 +19,45 @@ module Ci ...@@ -19,6 +19,45 @@ module Ci
after_save :keep_around_commits after_save :keep_around_commits
state_machine :status, initial: :created do
event :enqueue do
transition created: :pending
transition [:success, :failed, :canceled, :skipped] => :running
end
event :run do
transition any => :running
end
event :skip do
transition any => :skipped
end
event :drop do
transition any => :failed
end
event :succeed do
transition any => :success
end
event :cancel do
transition any => :canceled
end
before_transition [:created, :pending] => :running do |pipeline|
pipeline.started_at = Time.now
end
before_transition any => [:success, :failed, :canceled] do |pipeline|
pipeline.finished_at = Time.now
end
before_transition do |pipeline|
pipeline.update_duration
end
end
# ref can't be HEAD or SHA, can only be branch/tag name # ref can't be HEAD or SHA, can only be branch/tag name
scope :latest_successful_for, ->(ref = default_branch) do scope :latest_successful_for, ->(ref = default_branch) do
where(ref: ref).success.order(id: :desc).limit(1) where(ref: ref).success.order(id: :desc).limit(1)
...@@ -89,16 +128,12 @@ module Ci ...@@ -89,16 +128,12 @@ module Ci
def cancel_running def cancel_running
builds.running_or_pending.each(&:cancel) builds.running_or_pending.each(&:cancel)
reload_status!
end end
def retry_failed(user) def retry_failed(user)
builds.latest.failed.select(&:retryable?).each do |build| builds.latest.failed.select(&:retryable?).each do |build|
Ci::Build.retry(build, user) Ci::Build.retry(build, user)
end end
reload_status!
end end
def latest? def latest?
...@@ -185,7 +220,17 @@ module Ci ...@@ -185,7 +220,17 @@ module Ci
def process! def process!
Ci::ProcessPipelineService.new(project, user).execute(self) Ci::ProcessPipelineService.new(project, user).execute(self)
reload_status! end
def build_updated
case latest_builds_status
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 end
def predefined_variables def predefined_variables
...@@ -194,22 +239,18 @@ module Ci ...@@ -194,22 +239,18 @@ module Ci
] ]
end end
def reload_status! def update_duration
statuses.reload
self.status =
if yaml_errors.blank?
statuses.latest.status || 'skipped'
else
'failed'
end
self.started_at = statuses.started_at
self.finished_at = statuses.finished_at
self.duration = statuses.latest.duration self.duration = statuses.latest.duration
save
end end
private private
def latest_builds_status
return 'failed' unless yaml_errors.blank?
statuses.latest.status || 'skipped'
end
def keep_around_commits def keep_around_commits
return unless project return unless project
......
...@@ -26,7 +26,7 @@ class CommitStatus < ActiveRecord::Base ...@@ -26,7 +26,7 @@ class CommitStatus < ActiveRecord::Base
scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) } scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) }
state_machine :status do state_machine :status do
event :queue do event :enqueue do
transition [:created, :skipped] => :pending transition [:created, :skipped] => :pending
end end
...@@ -62,6 +62,17 @@ class CommitStatus < ActiveRecord::Base ...@@ -62,6 +62,17 @@ class CommitStatus < ActiveRecord::Base
commit_status.update_attributes finished_at: Time.now commit_status.update_attributes finished_at: Time.now
end end
# We use around_transition to process pipeline on next stages as soon as possible, before the `after_*` is executed
around_transition any => [:success, :failed, :canceled] do |commit_status, block|
block.call
commit_status.pipeline.try(:process!)
end
after_transition do |commit_status, transition|
commit_status.pipeline.try(:build_updated) unless transition.loopback?
end
after_transition [:created, :pending, :running] => :success do |commit_status| after_transition [:created, :pending, :running] => :success do |commit_status|
MergeRequests::MergeWhenBuildSucceedsService.new(commit_status.pipeline.project, nil).trigger(commit_status) MergeRequests::MergeWhenBuildSucceedsService.new(commit_status.pipeline.project, nil).trigger(commit_status)
end end
...@@ -69,13 +80,6 @@ class CommitStatus < ActiveRecord::Base ...@@ -69,13 +80,6 @@ class CommitStatus < ActiveRecord::Base
after_transition any => :failed do |commit_status| after_transition any => :failed do |commit_status|
MergeRequests::AddTodoWhenBuildFailsService.new(commit_status.pipeline.project, nil).execute(commit_status) MergeRequests::AddTodoWhenBuildFailsService.new(commit_status.pipeline.project, nil).execute(commit_status)
end end
# We use around_transition to process pipeline on next stages as soon as possible, before the `after_*` is executed
around_transition any => [:success, :failed, :canceled] do |commit_status, block|
block.call
commit_status.pipeline.process! if commit_status.pipeline
end
end end
delegate :sha, :short_sha, to: :pipeline delegate :sha, :short_sha, to: :pipeline
......
class Namespace < ActiveRecord::Base class Namespace < ActiveRecord::Base
acts_as_paranoid
include Sortable include Sortable
include Gitlab::ShellAdapter include Gitlab::ShellAdapter
......
...@@ -37,7 +37,8 @@ module Ci ...@@ -37,7 +37,8 @@ module Ci
end end
if !ignore_skip_ci && skip_ci? if !ignore_skip_ci && skip_ci?
return error('Creation of pipeline is skipped', save: save_on_errors) pipeline.skip if save_on_errors
return pipeline
end end
unless pipeline.config_builds_attributes.present? unless pipeline.config_builds_attributes.present?
...@@ -93,7 +94,7 @@ module Ci ...@@ -93,7 +94,7 @@ module Ci
def error(message, save: false) def error(message, save: false)
pipeline.errors.add(:base, message) pipeline.errors.add(:base, message)
pipeline.reload_status! if save pipeline.drop if save
pipeline pipeline
end end
end end
......
...@@ -37,7 +37,7 @@ module Ci ...@@ -37,7 +37,7 @@ module Ci
return false unless Statuseable::COMPLETED_STATUSES.include?(current_status) return false unless Statuseable::COMPLETED_STATUSES.include?(current_status)
if valid_statuses_for_when(build.when).include?(current_status) if valid_statuses_for_when(build.when).include?(current_status)
build.queue build.enqueue
true true
else else
build.skip build.skip
......
...@@ -21,6 +21,11 @@ class DeleteUserService ...@@ -21,6 +21,11 @@ class DeleteUserService
::Projects::DestroyService.new(project, current_user, skip_repo: true).async_execute ::Projects::DestroyService.new(project, current_user, skip_repo: true).async_execute
end end
user.destroy # Destroy the namespace after destroying the user since certain methods may depend on the namespace existing
namespace = user.namespace
user_data = user.destroy
namespace.really_destroy!
user_data
end end
end end
...@@ -5,13 +5,23 @@ class DestroyGroupService ...@@ -5,13 +5,23 @@ class DestroyGroupService
@group, @current_user = group, user @group, @current_user = group, user
end end
def async_execute
group.transaction do
# Soft delete via paranoia gem
group.destroy
job_id = GroupDestroyWorker.perform_async(group.id, current_user.id)
Rails.logger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}")
end
end
def execute def execute
group.projects.each do |project| group.projects.each do |project|
# Execute the destruction of the models immediately to ensure atomic cleanup.
# Skip repository removal because we remove directory with namespace # Skip repository removal because we remove directory with namespace
# that contain all this repositories # that contain all these repositories
::Projects::DestroyService.new(project, current_user, skip_repo: true).async_execute ::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
end end
group.destroy group.really_destroy!
end end
end end
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
.pull-right .pull-right
- actions = deployment.manual_actions - actions = deployment.manual_actions
- if actions.present? - if actions.present?
.btn-group.inline .inline
.btn-group .dropdown
%a.dropdown-toggle.btn.btn-default{type: 'button', 'data-toggle' => 'dropdown'} %a.dropdown-new.btn.btn-default{type: 'button', 'data-toggle' => 'dropdown'}
= icon("play") = icon("play")
%b.caret %b.caret
%ul.dropdown-menu.dropdown-menu-align-right %ul.dropdown-menu.dropdown-menu-align-right
......
%div.branch-commit %div.branch-commit
- if deployment.ref - if deployment.ref
= link_to deployment.ref, namespace_project_commits_path(@project.namespace, @project, deployment.ref), class: "monospace" .icon-container
&middot; = deployment.tag? ? icon('tag') : icon('code-fork')
= link_to deployment.ref, namespace_project_commits_path(@project.namespace, @project, deployment.ref), class: "monospace branch-name"
.icon-container
= custom_icon("icon_commit")
= link_to deployment.short_sha, namespace_project_commit_path(@project.namespace, @project, deployment.sha), class: "commit-id monospace" = link_to deployment.short_sha, namespace_project_commit_path(@project.namespace, @project, deployment.sha), class: "commit-id monospace"
%p.commit-title %p.commit-title
%span %span
- if commit_title = deployment.commit_title - if commit_title = deployment.commit_title
= author_avatar(deployment.commit, size: 20)
= link_to_gfm commit_title, namespace_project_commit_path(@project.namespace, @project, deployment.sha), class: "commit-row-message" = link_to_gfm commit_title, namespace_project_commit_path(@project.namespace, @project, deployment.sha), class: "commit-row-message"
- else - else
Cant find HEAD commit for this branch Cant find HEAD commit for this branch
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
%td %td
- if deployment.deployable - if deployment.deployable
= link_to [@project.namespace.becomes(Namespace), @project, deployment.deployable] do = link_to [@project.namespace.becomes(Namespace), @project, deployment.deployable] do
= user_avatar(user: deployment.user, size: 20)
= "#{deployment.deployable.name} (##{deployment.deployable.id})" = "#{deployment.deployable.name} (##{deployment.deployable.id})"
%td %td
......
...@@ -2,9 +2,13 @@ ...@@ -2,9 +2,13 @@
%tr.environment %tr.environment
%td %td
%strong
= link_to environment.name, namespace_project_environment_path(@project.namespace, @project, environment) = link_to environment.name, namespace_project_environment_path(@project.namespace, @project, environment)
%td
- if last_deployment
= user_avatar(user: last_deployment.user, size: 20)
%strong ##{last_deployment.id}
%td %td
- if last_deployment - if last_deployment
= render 'projects/deployments/commit', deployment: last_deployment = render 'projects/deployments/commit', deployment: last_deployment
......
...@@ -23,10 +23,11 @@ ...@@ -23,10 +23,11 @@
New environment New environment
- else - else
.table-holder .table-holder
%table.table.environments %table.table.builds.environments
%tbody %tbody
%th Environment %th Environment
%th Last deployment %th Last Deployment
%th Date %th Commit
%th
%th %th
= render @environments = render @environments
...@@ -23,13 +23,13 @@ ...@@ -23,13 +23,13 @@
= link_to "Read more", help_page_path("ci/environments"), class: "btn btn-success" = link_to "Read more", help_page_path("ci/environments"), class: "btn btn-success"
- else - else
.table-holder .table-holder
%table.table.environments %table.table.builds.environments
%thead %thead
%tr %tr
%th ID %th ID
%th Commit %th Commit
%th Build %th Build
%th Date %th
%th %th
= render @deployments = render @deployments
......
class GroupDestroyWorker
include Sidekiq::Worker
sidekiq_options queue: :default
def perform(group_id, user_id)
begin
group = Group.with_deleted.find(group_id)
rescue ActiveRecord::RecordNotFound
return
end
user = User.find(user_id)
DestroyGroupService.new(group, user).execute
end
end
...@@ -148,6 +148,9 @@ if Gitlab::Metrics.enabled? ...@@ -148,6 +148,9 @@ if Gitlab::Metrics.enabled?
config.instrument_methods(Gitlab::Highlight) config.instrument_methods(Gitlab::Highlight)
config.instrument_instance_methods(Gitlab::Highlight) config.instrument_instance_methods(Gitlab::Highlight)
# This is a Rails scope so we have to instrument it manually.
config.instrument_method(Project, :visible_to_user)
end end
GC::Profiler.enable GC::Profiler.enable
......
# rubocop:disable all # rubocop:disable all
class FixNamespaces < ActiveRecord::Migration class FixNamespaces < ActiveRecord::Migration
DOWNTIME = false
def up def up
Namespace.where('name <> path and type is null').each do |namespace| namespaces = exec_query('SELECT id, path FROM namespaces WHERE name <> path and type is null')
namespace.update_attribute(:name, namespace.path)
namespaces.each do |row|
id = row['id']
path = row['path']
exec_query("UPDATE namespaces SET name = '#{path}' WHERE id = #{id}")
end end
end end
......
class AddDeletedAtToNamespaces < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def change
add_column :namespaces, :deleted_at, :datetime
add_concurrent_index :namespaces, :deleted_at
end
end
...@@ -640,9 +640,11 @@ ActiveRecord::Schema.define(version: 20160810142633) do ...@@ -640,9 +640,11 @@ ActiveRecord::Schema.define(version: 20160810142633) do
t.boolean "share_with_group_lock", default: false t.boolean "share_with_group_lock", default: false
t.integer "visibility_level", default: 20, null: false t.integer "visibility_level", default: 20, null: false
t.boolean "request_access_enabled", default: true, null: false t.boolean "request_access_enabled", default: true, null: false
t.datetime "deleted_at"
end end
add_index "namespaces", ["created_at"], name: "index_namespaces_on_created_at", using: :btree add_index "namespaces", ["created_at"], name: "index_namespaces_on_created_at", using: :btree
add_index "namespaces", ["deleted_at"], name: "index_namespaces_on_deleted_at", using: :btree
add_index "namespaces", ["name"], name: "index_namespaces_on_name", unique: true, using: :btree add_index "namespaces", ["name"], name: "index_namespaces_on_name", unique: true, using: :btree
add_index "namespaces", ["name"], name: "index_namespaces_on_name_trigram", using: :gin, opclasses: {"name"=>"gin_trgm_ops"} add_index "namespaces", ["name"], name: "index_namespaces_on_name_trigram", using: :gin, opclasses: {"name"=>"gin_trgm_ops"}
add_index "namespaces", ["owner_id"], name: "index_namespaces_on_owner_id", using: :btree add_index "namespaces", ["owner_id"], name: "index_namespaces_on_owner_id", using: :btree
......
...@@ -12,7 +12,6 @@ module SharedBuilds ...@@ -12,7 +12,6 @@ module SharedBuilds
step 'project has a recent build' do step 'project has a recent build' do
@pipeline = create(:ci_empty_pipeline, project: @project, sha: @project.commit.sha, ref: 'master') @pipeline = create(:ci_empty_pipeline, project: @project, sha: @project.commit.sha, ref: 'master')
@build = create(:ci_build_with_coverage, pipeline: @pipeline) @build = create(:ci_build_with_coverage, pipeline: @pipeline)
@pipeline.reload_status!
end end
step 'recent build is successful' do step 'recent build is successful' do
...@@ -24,8 +23,7 @@ module SharedBuilds ...@@ -24,8 +23,7 @@ module SharedBuilds
end end
step 'project has another build that is running' do step 'project has another build that is running' do
create(:ci_build, pipeline: @pipeline, name: 'second build', status: 'running') create(:ci_build, pipeline: @pipeline, name: 'second build', status_event: 'run')
@pipeline.reload_status!
end end
step 'I visit recent build details page' do step 'I visit recent build details page' do
......
require 'spec_helper'
describe Admin::GroupsController do
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
let(:admin) { create(:admin) }
before do
sign_in(admin)
Sidekiq::Testing.fake!
end
describe 'DELETE #destroy' do
it 'schedules a group destroy' do
expect { delete :destroy, id: project.group.path }.to change(GroupDestroyWorker.jobs, :size).by(1)
end
it 'redirects to the admin group path' do
delete :destroy, id: project.group.path
expect(response).to redirect_to(admin_groups_path)
end
end
end
...@@ -75,4 +75,33 @@ describe GroupsController do ...@@ -75,4 +75,33 @@ describe GroupsController do
end end
end end
end end
describe 'DELETE #destroy' do
context 'as another user' do
it 'returns 404' do
sign_in(create(:user))
delete :destroy, id: group.path
expect(response.status).to eq(404)
end
end
context 'as the group owner' do
before do
Sidekiq::Testing.fake!
sign_in(user)
end
it 'schedules a group destroy' do
expect { delete :destroy, id: group.path }.to change(GroupDestroyWorker.jobs, :size).by(1)
end
it 'redirects to the root path' do
delete :destroy, id: group.path
expect(response).to redirect_to(root_path)
end
end
end
end end
...@@ -12,7 +12,7 @@ describe "Pipelines" do ...@@ -12,7 +12,7 @@ describe "Pipelines" do
end end
describe 'GET /:project/pipelines' do describe 'GET /:project/pipelines' do
let!(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', status: 'running') } let!(:pipeline) { create(:ci_empty_pipeline, project: project, ref: 'master', status: 'running') }
[:all, :running, :branches].each do |scope| [:all, :running, :branches].each do |scope|
context "displaying #{scope}" do context "displaying #{scope}" do
...@@ -31,10 +31,10 @@ describe "Pipelines" do ...@@ -31,10 +31,10 @@ describe "Pipelines" do
end end
context 'cancelable pipeline' do context 'cancelable pipeline' do
let!(:running) { create(:ci_build, :running, pipeline: pipeline, stage: 'test', commands: 'test') } let!(:build) { create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test') }
before do before do
pipeline.reload_status! build.run
visit namespace_project_pipelines_path(project.namespace, project) visit namespace_project_pipelines_path(project.namespace, project)
end end
...@@ -50,10 +50,10 @@ describe "Pipelines" do ...@@ -50,10 +50,10 @@ describe "Pipelines" do
end end
context 'retryable pipelines' do context 'retryable pipelines' do
let!(:failed) { create(:ci_build, :failed, pipeline: pipeline, stage: 'test', commands: 'test') } let!(:build) { create(:ci_build, pipeline: pipeline, stage: 'test', commands: 'test') }
before do before do
pipeline.reload_status! build.drop
visit namespace_project_pipelines_path(project.namespace, project) visit namespace_project_pipelines_path(project.namespace, project)
end end
...@@ -64,7 +64,7 @@ describe "Pipelines" do ...@@ -64,7 +64,7 @@ describe "Pipelines" do
before { click_link('Retry') } before { click_link('Retry') }
it { expect(page).not_to have_link('Retry') } it { expect(page).not_to have_link('Retry') }
it { expect(page).to have_selector('.ci-pending') } it { expect(page).to have_selector('.ci-running') }
end end
end end
...@@ -87,7 +87,6 @@ describe "Pipelines" do ...@@ -87,7 +87,6 @@ describe "Pipelines" do
let!(:running) { create(:generic_commit_status, status: 'running', pipeline: pipeline, stage: 'test') } let!(:running) { create(:generic_commit_status, status: 'running', pipeline: pipeline, stage: 'test') }
before do before do
pipeline.reload_status!
visit namespace_project_pipelines_path(project.namespace, project) visit namespace_project_pipelines_path(project.namespace, project)
end end
...@@ -101,10 +100,10 @@ describe "Pipelines" do ...@@ -101,10 +100,10 @@ describe "Pipelines" do
end end
context 'when failed' do context 'when failed' do
let!(:failed) { create(:generic_commit_status, status: 'failed', pipeline: pipeline, stage: 'test') } let!(:status) { create(:generic_commit_status, :pending, pipeline: pipeline, stage: 'test') }
before do before do
pipeline.reload_status! status.drop
visit namespace_project_pipelines_path(project.namespace, project) visit namespace_project_pipelines_path(project.namespace, project)
end end
......
...@@ -2,22 +2,23 @@ require 'spec_helper' ...@@ -2,22 +2,23 @@ require 'spec_helper'
describe Ci::Charts, lib: true do describe Ci::Charts, lib: true do
context "build_times" do context "build_times" do
let(:project) { create(:empty_project) }
let(:chart) { Ci::Charts::BuildTime.new(project) }
subject { chart.build_times }
before do before do
@pipeline = FactoryGirl.create(:ci_pipeline) create(:ci_empty_pipeline, project: project, duration: 120)
FactoryGirl.create(:ci_build, pipeline: @pipeline)
@pipeline.reload_status!
end end
it 'returns build times in minutes' do it 'returns build times in minutes' do
chart = Ci::Charts::BuildTime.new(@pipeline.project) is_expected.to contain_exactly(2)
expect(chart.build_times).to eq([2])
end end
it 'handles nil build times' do it 'handles nil build times' do
create(:ci_pipeline, duration: nil, project: @pipeline.project) create(:ci_empty_pipeline, project: project, duration: nil)
chart = Ci::Charts::BuildTime.new(@pipeline.project) is_expected.to contain_exactly(2, 0)
expect(chart.build_times).to eq([2, 0])
end end
end end
end end
...@@ -886,8 +886,10 @@ describe Ci::Build, models: true do ...@@ -886,8 +886,10 @@ describe Ci::Build, models: true do
is_expected.to eq(build) is_expected.to eq(build)
end end
context 'for success build' do context 'for successful build' do
before { build.queue } before do
build.update(status: 'success')
end
it 'creates a new build' do it 'creates a new build' do
is_expected.to be_pending is_expected.to be_pending
......
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe Ci::Pipeline, models: true do describe Ci::Pipeline, models: true do
let(:project) { FactoryGirl.create :empty_project } let(:project) { FactoryGirl.create :empty_project }
let(:pipeline) { FactoryGirl.create :ci_pipeline, project: project } let(:pipeline) { FactoryGirl.create :ci_empty_pipeline, project: project }
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:user) }
...@@ -51,25 +51,6 @@ describe Ci::Pipeline, models: true do ...@@ -51,25 +51,6 @@ describe Ci::Pipeline, models: true do
end end
end end
describe "#finished_at" do
let(:pipeline) { FactoryGirl.create :ci_pipeline }
it "returns finished_at of latest build" do
build = FactoryGirl.create :ci_build, pipeline: pipeline, finished_at: Time.now - 60
FactoryGirl.create :ci_build, pipeline: pipeline, finished_at: Time.now - 120
pipeline.reload_status!
expect(pipeline.finished_at.to_i).to eq(build.finished_at.to_i)
end
it "returns nil if there is no finished build" do
FactoryGirl.create :ci_not_started_build, pipeline: pipeline
pipeline.reload_status!
expect(pipeline.finished_at).to be_nil
end
end
describe "coverage" do describe "coverage" do
let(:project) { FactoryGirl.create :empty_project, build_coverage_regex: "/.*/" } let(:project) { FactoryGirl.create :empty_project, build_coverage_regex: "/.*/" }
let(:pipeline) { FactoryGirl.create :ci_empty_pipeline, project: project } let(:pipeline) { FactoryGirl.create :ci_empty_pipeline, project: project }
...@@ -139,33 +120,48 @@ describe Ci::Pipeline, models: true do ...@@ -139,33 +120,48 @@ describe Ci::Pipeline, models: true do
end end
end end
describe '#reload_status!' do describe 'state machine' do
let(:pipeline) { create :ci_empty_pipeline, project: project } let(:current) { Time.now.change(usec: 0) }
let(:build) { create :ci_build, name: 'build1', pipeline: pipeline, started_at: current - 60, finished_at: current }
context 'dependent objects' do let(:build2) { create :ci_build, name: 'build2', pipeline: pipeline, started_at: current - 60, finished_at: current }
let(:commit_status) { create :commit_status, :pending, pipeline: pipeline }
it 'executes reload_status! after succeeding dependent object' do describe '#duration' do
expect(pipeline).to receive(:reload_status!).and_return(true) before do
build.skip
build2.skip
end
commit_status.success it 'matches sum of builds duration' do
expect(pipeline.reload.duration).to eq(build.duration + build2.duration)
end end
end end
context 'updates' do describe '#started_at' do
let(:current) { Time.now.change(usec: 0) } it 'updates on transitioning to running' do
let(:build) { FactoryGirl.create :ci_build, pipeline: pipeline, started_at: current - 120, finished_at: current - 60 } build.run
before do expect(pipeline.reload.started_at).not_to be_nil
build
pipeline.reload_status!
end end
[:status, :started_at, :finished_at, :duration].each do |param| it 'does not update on transitioning to success' do
it "#{param}" do build.success
expect(pipeline.send(param)).to eq(build.send(param))
expect(pipeline.reload.started_at).to be_nil
end end
end end
describe '#finished_at' do
it 'updates on transitioning to success' do
build.success
expect(pipeline.reload.finished_at).not_to be_nil
end
it 'does not update on transitioning to running' do
build.run
expect(pipeline.reload.finished_at).to be_nil
end
end end
end end
...@@ -254,4 +250,64 @@ describe Ci::Pipeline, models: true do ...@@ -254,4 +250,64 @@ describe Ci::Pipeline, models: true do
end end
end end
end end
describe '#status' do
let!(:build) { create(:ci_build, :created, pipeline: pipeline, name: 'test') }
subject { pipeline.reload.status }
context 'on queuing' do
before do
build.enqueue
end
it { is_expected.to eq('pending') }
end
context 'on run' do
before do
build.enqueue
build.run
end
it { is_expected.to eq('running') }
end
context 'on drop' do
before do
build.drop
end
it { is_expected.to eq('failed') }
end
context 'on success' do
before do
build.success
end
it { is_expected.to eq('success') }
end
context 'on cancel' do
before do
build.cancel
end
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 end
...@@ -9,7 +9,7 @@ describe API::API, api: true do ...@@ -9,7 +9,7 @@ describe API::API, api: true do
let!(:developer) { create(:project_member, :developer, user: user, project: project) } let!(:developer) { create(:project_member, :developer, user: user, project: project) }
let(:reporter) { create(:project_member, :reporter, project: project) } let(:reporter) { create(:project_member, :reporter, project: project) }
let(:guest) { create(:project_member, :guest, project: project) } let(:guest) { create(:project_member, :guest, project: project) }
let!(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) } let!(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) }
let!(:build) { create(:ci_build, pipeline: pipeline) } let!(:build) { create(:ci_build, pipeline: pipeline) }
describe 'GET /projects/:id/builds ' do describe 'GET /projects/:id/builds ' do
...@@ -174,7 +174,11 @@ describe API::API, api: true do ...@@ -174,7 +174,11 @@ describe API::API, api: true do
describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do
let(:api_user) { reporter.user } let(:api_user) { reporter.user }
let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) } let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) }
before do
build.success
end
def path_for_ref(ref = pipeline.ref, job = build.name) def path_for_ref(ref = pipeline.ref, job = build.name)
api("/projects/#{project.id}/builds/artifacts/#{ref}/download?job=#{job}", api_user) api("/projects/#{project.id}/builds/artifacts/#{ref}/download?job=#{job}", api_user)
...@@ -238,10 +242,6 @@ describe API::API, api: true do ...@@ -238,10 +242,6 @@ describe API::API, api: true do
it { expect(response.headers).to include(download_headers) } it { expect(response.headers).to include(download_headers) }
end end
before do
pipeline.reload_status!
end
context 'with regular branch' do context 'with regular branch' do
before do before do
pipeline.update(ref: 'master', pipeline.update(ref: 'master',
......
...@@ -564,12 +564,14 @@ describe API::API, api: true do ...@@ -564,12 +564,14 @@ describe API::API, api: true do
end end
describe "DELETE /users/:id" do describe "DELETE /users/:id" do
let!(:namespace) { user.namespace }
before { admin } before { admin }
it "deletes user" do it "deletes user" do
delete api("/users/#{user.id}", admin) delete api("/users/#{user.id}", admin)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect { User.find(user.id) }.to raise_error ActiveRecord::RecordNotFound expect { User.find(user.id) }.to raise_error ActiveRecord::RecordNotFound
expect { Namespace.find(namespace.id) }.to raise_error ActiveRecord::RecordNotFound
expect(json_response['email']).to eq(user.email) expect(json_response['email']).to eq(user.email)
end end
......
...@@ -14,7 +14,6 @@ module Ci ...@@ -14,7 +14,6 @@ module Ci
context 'branch name' do context 'branch name' do
before { allow(project).to receive(:commit).and_return(OpenStruct.new(sha: commit_sha)) } before { allow(project).to receive(:commit).and_return(OpenStruct.new(sha: commit_sha)) }
before { build.run! } before { build.run! }
before { pipeline.reload_status! }
let(:image) { service.execute(project, ref: 'master') } let(:image) { service.execute(project, ref: 'master') }
it { expect(image).to be_kind_of(OpenStruct) } it { expect(image).to be_kind_of(OpenStruct) }
...@@ -32,7 +31,6 @@ module Ci ...@@ -32,7 +31,6 @@ module Ci
context 'commit sha' do context 'commit sha' do
before { build.run! } before { build.run! }
before { pipeline.reload_status! }
let(:image) { service.execute(project, sha: build.sha) } let(:image) { service.execute(project, sha: build.sha) }
it { expect(image).to be_kind_of(OpenStruct) } it { expect(image).to be_kind_of(OpenStruct) }
......
...@@ -9,9 +9,11 @@ describe DeleteUserService, services: true do ...@@ -9,9 +9,11 @@ describe DeleteUserService, services: true do
context 'no options are given' do context 'no options are given' do
it 'deletes the user' do it 'deletes the user' do
DeleteUserService.new(current_user).execute(user) user_data = DeleteUserService.new(current_user).execute(user)
expect { user_data['email'].to eq(user.email) }
expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound) expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
expect { Namespace.with_deleted.find(user.namespace.id) }.to raise_error(ActiveRecord::RecordNotFound)
end end
it 'will delete the project in the near future' do it 'will delete the project in the near future' do
......
...@@ -7,9 +7,10 @@ describe DestroyGroupService, services: true do ...@@ -7,9 +7,10 @@ describe DestroyGroupService, services: true do
let!(:gitlab_shell) { Gitlab::Shell.new } let!(:gitlab_shell) { Gitlab::Shell.new }
let!(:remove_path) { group.path + "+#{group.id}+deleted" } let!(:remove_path) { group.path + "+#{group.id}+deleted" }
shared_examples 'group destruction' do |async|
context 'database records' do context 'database records' do
before do before do
destroy_group(group, user) destroy_group(group, user, async)
end end
it { expect(Group.all).not_to include(group) } it { expect(Group.all).not_to include(group) }
...@@ -20,7 +21,7 @@ describe DestroyGroupService, services: true do ...@@ -20,7 +21,7 @@ describe DestroyGroupService, services: true do
context 'Sidekiq inline' do context 'Sidekiq inline' do
before do before do
# Run sidekiq immediatly to check that renamed dir will be removed # Run sidekiq immediatly to check that renamed dir will be removed
Sidekiq::Testing.inline! { destroy_group(group, user) } Sidekiq::Testing.inline! { destroy_group(group, user, async) }
end end
it { expect(gitlab_shell.exists?(project.repository_storage_path, group.path)).to be_falsey } it { expect(gitlab_shell.exists?(project.repository_storage_path, group.path)).to be_falsey }
...@@ -30,7 +31,7 @@ describe DestroyGroupService, services: true do ...@@ -30,7 +31,7 @@ describe DestroyGroupService, services: true do
context 'Sidekiq fake' do context 'Sidekiq fake' do
before do before do
# Dont run sidekiq to check if renamed repository exists # Dont run sidekiq to check if renamed repository exists
Sidekiq::Testing.fake! { destroy_group(group, user) } Sidekiq::Testing.fake! { destroy_group(group, user, async) }
end end
it { expect(gitlab_shell.exists?(project.repository_storage_path, group.path)).to be_falsey } it { expect(gitlab_shell.exists?(project.repository_storage_path, group.path)).to be_falsey }
...@@ -38,7 +39,20 @@ describe DestroyGroupService, services: true do ...@@ -38,7 +39,20 @@ describe DestroyGroupService, services: true do
end end
end end
def destroy_group(group, user) def destroy_group(group, user, async)
if async
DestroyGroupService.new(group, user).async_execute
else
DestroyGroupService.new(group, user).execute DestroyGroupService.new(group, user).execute
end end
end
end
describe 'asynchronous delete' do
it_behaves_like 'group destruction', true
end
describe 'synchronous delete' do
it_behaves_like 'group destruction', false
end
end end
require 'spec_helper'
describe GroupDestroyWorker do
let(:group) { create(:group) }
let(:user) { create(:admin) }
let!(:project) { create(:project, namespace: group) }
subject { GroupDestroyWorker.new }
describe "#perform" do
it "deletes the project" do
subject.perform(group.id, user.id)
expect(Group.all).not_to include(group)
expect(Project.all).not_to include(project)
expect(Dir.exist?(project.path)).to be_falsey
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment