Commit 956c55e2 authored by Robert Speicher's avatar Robert Speicher

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
parents a403011e 45647951
...@@ -971,9 +971,9 @@ class Project < ActiveRecord::Base ...@@ -971,9 +971,9 @@ class Project < ActiveRecord::Base
hooks.hooks_for(hooks_scope).each do |hook| hooks.hooks_for(hooks_scope).each do |hook|
hook.async_execute(data, hooks_scope.to_s) hook.async_execute(data, hooks_scope.to_s)
end end
end
SystemHooksService.new.execute_hooks(data, hooks_scope) SystemHooksService.new.execute_hooks(data, hooks_scope)
end
end end
def execute_services(data, hooks_scope = :push_hooks) def execute_services(data, hooks_scope = :push_hooks)
......
---
title: Execute system hooks after-commit when executing project hooks
merge_request:
author:
type: fixed
...@@ -3228,5 +3228,22 @@ describe Project do ...@@ -3228,5 +3228,22 @@ describe Project do
project = build(:project) project = build(:project)
project.execute_hooks({ data: 'data' }, :merge_request_hooks) project.execute_hooks({ data: 'data' }, :merge_request_hooks)
end 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
end end
...@@ -297,9 +297,11 @@ describe Issues::MoveService do ...@@ -297,9 +297,11 @@ describe Issues::MoveService do
end end
context 'project issue hooks' do 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 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, # Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
# but since the entire spec run takes place in a transaction, we never # but since the entire spec run takes place in a transaction, we never
# actually get to the `after_commit` hook that queues these jobs. # actually get to the `after_commit` hook that queues these jobs.
......
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