summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-09-14 14:56:13 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-09-14 14:56:13 +0000
commitc0c314c6bfe3640d724955d7d4eae7b9f7e1d2b1 (patch)
tree3923e3cb650f4e5873c50326a21941e789ca69af /spec
parente72b9ffe98996e8fb7a104ab4b1ce8671b1186c8 (diff)
parent9995f0806b29934cf498607f59d2c5ec358a0d5a (diff)
downloadgitlab-ce-c0c314c6bfe3640d724955d7d4eae7b9f7e1d2b1.tar.gz
Merge branch 'forked-repo-creation-async' into 'master'
Import forked repositories asynchronously to prevent large repositories from timing out Preserve synchronous mode of adding a repository since some tasks (e.g. restore/check) require the former. One side bug fix is that the `ProjectCacheWorker` is also run, updating the repository size and commit numbers properly. Previously all the values were set to 0 when a project were forked. * Closes #2388 * Closes #2400 See merge request !1231
Diffstat (limited to 'spec')
-rw-r--r--spec/services/projects/create_service_spec.rb11
-rw-r--r--spec/services/projects/fork_service_spec.rb5
-rw-r--r--spec/workers/repository_fork_worker_spec.rb29
3 files changed, 42 insertions, 3 deletions
diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb
index ff4ed2dd484..25277f07482 100644
--- a/spec/services/projects/create_service_spec.rb
+++ b/spec/services/projects/create_service_spec.rb
@@ -96,6 +96,17 @@ describe Projects::CreateService do
expect(project.saved?).to be(true)
end
end
+
+ context 'repository creation' do
+ it 'should synchronously create the repository' do
+ expect_any_instance_of(Project).to receive(:create_repository)
+
+ project = create_project(@user, @opts)
+ expect(project).to be_valid
+ expect(project.owner).to eq(@user)
+ expect(project.namespace).to eq(@user.namespace)
+ end
+ end
end
def create_project(user, opts)
diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb
index c04e842c67e..7c4bb74b77f 100644
--- a/spec/services/projects/fork_service_spec.rb
+++ b/spec/services/projects/fork_service_spec.rb
@@ -28,8 +28,7 @@ describe Projects::ForkService do
context 'fork project failure' do
it "fails due to transaction failure" do
@to_project = fork_project(@from_project, @to_user, false)
- expect(@to_project.errors).not_to be_empty
- expect(@to_project.errors[:base]).to include("Failed to fork repository via gitlab-shell")
+ expect(@to_project.import_failed?)
end
end
@@ -100,7 +99,7 @@ describe Projects::ForkService do
end
def fork_project(from_project, user, fork_success = true, params = {})
- allow_any_instance_of(Gitlab::Shell).to receive(:fork_repository).and_return(fork_success)
+ allow(RepositoryForkWorker).to receive(:perform_async).and_return(fork_success)
Projects::ForkService.new(from_project, user, params).execute
end
end
diff --git a/spec/workers/repository_fork_worker_spec.rb b/spec/workers/repository_fork_worker_spec.rb
new file mode 100644
index 00000000000..aa031106968
--- /dev/null
+++ b/spec/workers/repository_fork_worker_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe RepositoryForkWorker do
+ let(:project) { create(:project) }
+ let(:fork_project) { create(:project, forked_from_project: project) }
+
+ subject { RepositoryForkWorker.new }
+
+ describe "#perform" do
+ it "creates a new repository from a fork" do
+ expect_any_instance_of(Gitlab::Shell).to receive(:fork_repository).with(
+ project.path_with_namespace,
+ fork_project.namespace.path).
+ and_return(true)
+ expect(ProjectCacheWorker).to receive(:perform_async)
+
+ subject.perform(project.id,
+ project.path_with_namespace,
+ fork_project.namespace.path)
+ end
+
+ it "handles bad fork" do
+ expect_any_instance_of(Gitlab::Shell).to receive(:fork_repository).and_return(false)
+ subject.perform(project.id,
+ project.path_with_namespace,
+ fork_project.namespace.path)
+ end
+ end
+end