Merge branch 'dm-project-system-hooks-in-transaction' into 'master'
Execute system hooks after-commit when executing project hooks See merge request gitlab-org/gitlab-ce!16673
This commit is contained in:
commit
956c55e2ab
4 changed files with 27 additions and 3 deletions
|
@ -971,10 +971,10 @@ class Project < ActiveRecord::Base
|
|||
hooks.hooks_for(hooks_scope).each do |hook|
|
||||
hook.async_execute(data, hooks_scope.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
SystemHooksService.new.execute_hooks(data, hooks_scope)
|
||||
end
|
||||
end
|
||||
|
||||
def execute_services(data, hooks_scope = :push_hooks)
|
||||
# Call only service hooks that are active for this scope
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Execute system hooks after-commit when executing project hooks
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -3228,5 +3228,22 @@ describe Project do
|
|||
project = build(:project)
|
||||
project.execute_hooks({ data: 'data' }, :merge_request_hooks)
|
||||
end
|
||||
|
||||
it 'executes the system hooks when inside a transaction' do
|
||||
allow_any_instance_of(WebHookService).to receive(:execute)
|
||||
|
||||
create(:system_hook, merge_requests_events: true)
|
||||
|
||||
project = build(:project)
|
||||
|
||||
# Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
|
||||
# but since the entire spec run takes place in a transaction, we never
|
||||
# actually get to the `after_commit` hook that queues these jobs.
|
||||
expect do
|
||||
project.transaction do
|
||||
project.execute_hooks({ data: 'data' }, :merge_request_hooks)
|
||||
end
|
||||
end.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -297,9 +297,11 @@ describe Issues::MoveService do
|
|||
end
|
||||
|
||||
context 'project issue hooks' do
|
||||
let(:hook) { create(:project_hook, project: old_project, issues_events: true) }
|
||||
let!(:hook) { create(:project_hook, project: old_project, issues_events: true) }
|
||||
|
||||
it 'executes project issue hooks' do
|
||||
allow_any_instance_of(WebHookService).to receive(:execute)
|
||||
|
||||
# Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
|
||||
# but since the entire spec run takes place in a transaction, we never
|
||||
# actually get to the `after_commit` hook that queues these jobs.
|
||||
|
|
Loading…
Reference in a new issue