Commit 3463ffde authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'push-ref' into 'master'

Fix high CPU usage when PostReceive receives refs/merge-requests/<id>

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/12661


See merge request !3651
parents 94e130ce af25001d
...@@ -37,6 +37,7 @@ v 8.7.0 (unreleased) ...@@ -37,6 +37,7 @@ v 8.7.0 (unreleased)
- API: Delete notes of issues, snippets, and merge requests (Robert Schilling) - API: Delete notes of issues, snippets, and merge requests (Robert Schilling)
- Implement 'Groups View' as an option for dashboard preferences !3379 (Elias W.) - Implement 'Groups View' as an option for dashboard preferences !3379 (Elias W.)
- Better errors handling when creating milestones inside groups - Better errors handling when creating milestones inside groups
- Fix high CPU usage when PostReceive receives refs/merge-requests/<id>
- Hide `Create a group` help block when creating a new project in a group - Hide `Create a group` help block when creating a new project in a group
- Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.) - Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.)
- Gracefully handle notes on deleted commits in merge requests (Stan Hu) - Gracefully handle notes on deleted commits in merge requests (Stan Hu)
......
...@@ -40,7 +40,7 @@ class PostReceive ...@@ -40,7 +40,7 @@ class PostReceive
if Gitlab::Git.tag_ref?(ref) if Gitlab::Git.tag_ref?(ref)
GitTagPushService.new.execute(post_received.project, @user, oldrev, newrev, ref) GitTagPushService.new.execute(post_received.project, @user, oldrev, newrev, ref)
else elsif Gitlab::Git.branch_ref?(ref)
GitPushService.new(post_received.project, @user, oldrev: oldrev, newrev: newrev, ref: ref).execute GitPushService.new(post_received.project, @user, oldrev: oldrev, newrev: newrev, ref: ref).execute
end end
end end
......
...@@ -4,6 +4,9 @@ describe PostReceive do ...@@ -4,6 +4,9 @@ describe PostReceive do
let(:changes) { "123456 789012 refs/heads/tést\n654321 210987 refs/tags/tag" } let(:changes) { "123456 789012 refs/heads/tést\n654321 210987 refs/tags/tag" }
let(:wrongly_encoded_changes) { changes.encode("ISO-8859-1").force_encoding("UTF-8") } let(:wrongly_encoded_changes) { changes.encode("ISO-8859-1").force_encoding("UTF-8") }
let(:base64_changes) { Base64.encode64(wrongly_encoded_changes) } let(:base64_changes) { Base64.encode64(wrongly_encoded_changes) }
let(:project) { create(:project) }
let(:key) { create(:key, user: project.owner) }
let(:key_id) { key.shell_id }
context "as a resque worker" do context "as a resque worker" do
it "reponds to #perform" do it "reponds to #perform" do
...@@ -11,11 +14,43 @@ describe PostReceive do ...@@ -11,11 +14,43 @@ describe PostReceive do
end end
end end
context "webhook" do describe "#process_project_changes" do
let(:project) { create(:project) } before do
let(:key) { create(:key, user: project.owner) } allow_any_instance_of(Gitlab::GitPostReceive).to receive(:identify).and_return(project.owner)
let(:key_id) { key.shell_id } end
context "branches" do
let(:changes) { "123456 789012 refs/heads/tést" }
it "should call GitTagPushService" do
expect_any_instance_of(GitPushService).to receive(:execute).and_return(true)
expect_any_instance_of(GitTagPushService).not_to receive(:execute)
PostReceive.new.perform(pwd(project), key_id, base64_changes)
end
end
context "tags" do
let(:changes) { "123456 789012 refs/tags/tag" }
it "should call GitTagPushService" do
expect_any_instance_of(GitPushService).not_to receive(:execute)
expect_any_instance_of(GitTagPushService).to receive(:execute).and_return(true)
PostReceive.new.perform(pwd(project), key_id, base64_changes)
end
end
context "merge-requests" do
let(:changes) { "123456 789012 refs/merge-requests/123" }
it "should not call any of the services" do
expect_any_instance_of(GitPushService).not_to receive(:execute)
expect_any_instance_of(GitTagPushService).not_to receive(:execute)
PostReceive.new.perform(pwd(project), key_id, base64_changes)
end
end
end
context "webhook" do
it "fetches the correct project" do it "fetches the correct project" do
expect(Project).to receive(:find_with_namespace).with(project.path_with_namespace).and_return(project) expect(Project).to receive(:find_with_namespace).with(project.path_with_namespace).and_return(project)
PostReceive.new.perform(pwd(project), key_id, base64_changes) PostReceive.new.perform(pwd(project), key_id, base64_changes)
......
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