Read about our upcoming Code of Conduct on this issue

Commit 1b317374 authored by Tiago Botelho's avatar Tiago Botelho
Browse files

Removes all the irrelevant import related code and columns

Clears the import related columns and code from the Project
model over to the ProjectImportState model
parent 2c51eecfe5be
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
end end
it 'is not scheduled' do it 'is not scheduled' do
expect(project.import_scheduled?).to be(false) expect(project.import_scheduled?).to be_nil
end end
it 'repository is empty' do it 'repository is empty' do
......
...@@ -58,14 +58,16 @@ ...@@ -58,14 +58,16 @@
end end
describe '#find_project' do describe '#find_project' do
let(:import_state) { create(:import_state, project: project) }
it 'returns a Project for an existing ID' do it 'returns a Project for an existing ID' do
project.update_column(:import_status, 'started') import_state.update_column(:status, 'started')
expect(worker.find_project(project.id)).to eq(project) expect(worker.find_project(project.id)).to eq(project)
end end
it 'returns nil for a project that failed importing' do it 'returns nil for a project that failed importing' do
project.update_column(:import_status, 'failed') import_state.update_column(:status, 'failed')
expect(worker.find_project(project.id)).to be_nil expect(worker.find_project(project.id)).to be_nil
end end
......
...@@ -28,13 +28,23 @@ ...@@ -28,13 +28,23 @@
worker_class.sidekiq_retries_exhausted_block.call(job) worker_class.sidekiq_retries_exhausted_block.call(job)
expect(project.reload.import_error).to include("fork") expect(project.import_state.reload.last_error).to include("fork")
end end
it 'logs the appropriate error message for forked projects' do it 'logs the appropriate error message for forked projects' do
worker_class.sidekiq_retries_exhausted_block.call(job) worker_class.sidekiq_retries_exhausted_block.call(job)
expect(project.reload.import_error).to include("import") expect(project.import_state.reload.last_error).to include("import")
end
context 'when project does not have import_state' do
let(:project) { create(:project) }
it 'raises an error' do
expect do
worker_class.sidekiq_retries_exhausted_block.call(job)
end.to raise_error(NoMethodError)
end
end end
end end
end end
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
context 'when there are remaining jobs' do context 'when there are remaining jobs' do
before do before do
allow(worker) allow(worker)
.to receive(:find_project) .to receive(:find_import_state)
.and_return(project) .and_return(import_state)
end end
it 'reschedules itself' do it 'reschedules itself' do
...@@ -38,8 +38,8 @@ ...@@ -38,8 +38,8 @@
context 'when there are no remaining jobs' do context 'when there are no remaining jobs' do
before do before do
allow(worker) allow(worker)
.to receive(:find_project) .to receive(:find_import_state)
.and_return(project) .and_return(import_state)
allow(worker) allow(worker)
.to receive(:wait_for_jobs) .to receive(:wait_for_jobs)
...@@ -48,8 +48,8 @@ ...@@ -48,8 +48,8 @@
end end
it 'schedules the next stage' do it 'schedules the next stage' do
expect(project) expect(import_state)
.to receive(:refresh_import_jid_expiration) .to receive(:refresh_jid_expiration)
expect(Gitlab::GithubImport::Stage::FinishImportWorker) expect(Gitlab::GithubImport::Stage::FinishImportWorker)
.to receive(:perform_async) .to receive(:perform_async)
...@@ -96,22 +96,18 @@ ...@@ -96,22 +96,18 @@
end end
end end
describe '#find_project' do describe '#find_import_state' do
it 'returns a Project' do it 'returns a ProjectImportState' do
project.update_column(:import_status, 'started') import_state.update_column(:status, 'started')
found = worker.find_project(project.id) found = worker.find_import_state(project.id)
expect(found).to be_an_instance_of(Project) expect(found).to be_an_instance_of(ProjectImportState)
expect(found.attributes.keys).to match_array(%w(id jid))
# This test is there to make sure we only select the columns we care
# about.
# TODO: enable this assertion back again
# expect(found.attributes).to include({ 'id' => nil, 'import_jid' => '123' })
end end
it 'returns nil if the project import is not running' do it 'returns nil if the project import is not running' do
expect(worker.find_project(project.id)).to be_nil expect(worker.find_import_state(project.id)).to be_nil
end end
end end
end end
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
context 'when the job is running' do context 'when the job is running' do
it 'refreshes the import JID and reschedules itself' do it 'refreshes the import JID and reschedules itself' do
allow(worker) allow(worker)
.to receive(:find_project) .to receive(:find_import_state)
.with(project.id) .with(project.id)
.and_return(project) .and_return(project)
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
.and_return(true) .and_return(true)
expect(project) expect(project)
.to receive(:refresh_import_jid_expiration) .to receive(:refresh_jid_expiration)
expect(worker.class) expect(worker.class)
.to receive(:perform_in_the_future) .to receive(:perform_in_the_future)
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
context 'when the job is no longer running' do context 'when the job is no longer running' do
it 'returns' do it 'returns' do
allow(worker) allow(worker)
.to receive(:find_project) .to receive(:find_import_state)
.with(project.id) .with(project.id)
.and_return(project) .and_return(project)
...@@ -62,18 +62,18 @@ ...@@ -62,18 +62,18 @@
.and_return(false) .and_return(false)
expect(project) expect(project)
.not_to receive(:refresh_import_jid_expiration) .not_to receive(:refresh_jid_expiration)
worker.perform(project.id, '123') worker.perform(project.id, '123')
end end
end end
end end
describe '#find_project' do describe '#find_import_state' do
it 'returns a Project' do it 'returns a ProjectImportState' do
project = create(:project, :import_started) project = create(:project, :import_started)
expect(worker.find_project(project.id)).to be_an_instance_of(Project) expect(worker.find_import_state(project.id)).to be_an_instance_of(ProjectImportState)
end end
# it 'only selects the import JID field' do # it 'only selects the import JID field' do
...@@ -84,14 +84,14 @@ ...@@ -84,14 +84,14 @@
# .to eq({ 'id' => nil, 'import_jid' => '123abc' }) # .to eq({ 'id' => nil, 'import_jid' => '123abc' })
# end # end
it 'returns nil for a project for which the import process failed' do it 'returns nil for a import state for which the import process failed' do
project = create(:project, :import_failed) project = create(:project, :import_failed)
expect(worker.find_project(project.id)).to be_nil expect(worker.find_import_state(project.id)).to be_nil
end end
it 'returns nil for a non-existing project' do it 'returns nil for a non-existing find_import_state' do
expect(worker.find_project(-1)).to be_nil expect(worker.find_import_state(-1)).to be_nil
end end
end end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
describe Gitlab::GithubImport::Stage::ImportBaseDataWorker do describe Gitlab::GithubImport::Stage::ImportBaseDataWorker do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:import_state) { create(:import_state, project: project) }
let(:worker) { described_class.new } let(:worker) { described_class.new }
describe '#import' do describe '#import' do
...@@ -18,7 +19,7 @@ ...@@ -18,7 +19,7 @@
expect(importer).to receive(:execute) expect(importer).to receive(:execute)
end end
expect(project).to receive(:refresh_import_jid_expiration) expect(import_state).to receive(:refresh_jid_expiration)
expect(Gitlab::GithubImport::Stage::ImportPullRequestsWorker) expect(Gitlab::GithubImport::Stage::ImportPullRequestsWorker)
.to receive(:perform_async) .to receive(:perform_async)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:import_state) { create(:import_state, project: project) }
let(:worker) { described_class.new } let(:worker) { described_class.new }
describe '#import' do describe '#import' do
...@@ -19,8 +20,8 @@ ...@@ -19,8 +20,8 @@
.to receive(:execute) .to receive(:execute)
.and_return(waiter) .and_return(waiter)
expect(project) expect(import_state)
.to receive(:refresh_import_jid_expiration) .to receive(:refresh_jid_expiration)
expect(Gitlab::GithubImport::AdvanceStageWorker) expect(Gitlab::GithubImport::AdvanceStageWorker)
.to receive(:perform_async) .to receive(:perform_async)
......
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
describe '#perform' do describe '#perform' do
let(:project) { create(:project, :import_scheduled) } let(:project) { create(:project, :import_scheduled) }
let(:import_state) { project.import_state }
context 'when worker was reset without cleanup' do context 'when worker was reset without cleanup' do
it 'imports the project successfully' do it 'imports the project successfully' do
jid = '12345678' jid = '12345678'
started_project = create(:project) started_project = create(:project)
started_import_state = create(:import_state, :started, project: started_project, jid: jid)
create(:import_state, :started, project: started_project, jid: jid)
allow(subject).to receive(:jid).and_return(jid) allow(subject).to receive(:jid).and_return(jid)
...@@ -23,12 +23,12 @@ ...@@ -23,12 +23,12 @@
.and_return({ status: :ok }) .and_return({ status: :ok })
# Works around https://github.com/rspec/rspec-mocks/issues/910 # Works around https://github.com/rspec/rspec-mocks/issues/910
expect(Project).to receive(:find).with(project.id).and_return(project) expect(Project).to receive(:find).with(started_project.id).and_return(started_project)
expect(project.repository).to receive(:expire_emptiness_caches) expect(started_project.repository).to receive(:expire_emptiness_caches)
expect(project.wiki.repository).to receive(:expire_emptiness_caches) expect(started_project.wiki.repository).to receive(:expire_emptiness_caches)
expect(project).to receive(:import_finish) expect(started_import_state).to receive(:finish)
subject.perform(project.id) subject.perform(started_project.id)
end end
end end
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
expect(Project).to receive(:find).with(project.id).and_return(project) expect(Project).to receive(:find).with(project.id).and_return(project)
expect(project.repository).to receive(:expire_emptiness_caches) expect(project.repository).to receive(:expire_emptiness_caches)
expect(project.wiki.repository).to receive(:expire_emptiness_caches) expect(project.wiki.repository).to receive(:expire_emptiness_caches)
expect(project).to receive(:import_finish) expect(import_state).to receive(:finish)
subject.perform(project.id) subject.perform(project.id)
end end
...@@ -51,26 +51,27 @@ ...@@ -51,26 +51,27 @@
it 'hide the credentials that were used in the import URL' do it 'hide the credentials that were used in the import URL' do
error = %q{remote: Not Found fatal: repository 'https://user:pass@test.com/root/repoC.git/' not found } error = %q{remote: Not Found fatal: repository 'https://user:pass@test.com/root/repoC.git/' not found }
project.update(import_jid: '123') import_state.update(jid: '123')
expect_any_instance_of(Projects::ImportService).to receive(:execute).and_return({ status: :error, message: error }) expect_any_instance_of(Projects::ImportService).to receive(:execute).and_return({ status: :error, message: error })
expect do expect do
subject.perform(project.id) subject.perform(project.id)
end.to raise_error(RuntimeError, error) end.to raise_error(RuntimeError, error)
expect(project.reload.import_jid).not_to be_nil expect(import_state.reload.jid).not_to be_nil
end end
it 'updates the error on Import/Export' do it 'updates the error on Import/Export' do
error = %q{remote: Not Found fatal: repository 'https://user:pass@test.com/root/repoC.git/' not found } error = %q{remote: Not Found fatal: repository 'https://user:pass@test.com/root/repoC.git/' not found }
project.update(import_jid: '123', import_type: 'gitlab_project') project.update(import_type: 'gitlab_project')
import_state.update(jid: '123')
expect_any_instance_of(Projects::ImportService).to receive(:execute).and_return({ status: :error, message: error }) expect_any_instance_of(Projects::ImportService).to receive(:execute).and_return({ status: :error, message: error })
expect do expect do
subject.perform(project.id) subject.perform(project.id)
end.to raise_error(RuntimeError, error) end.to raise_error(RuntimeError, error)
expect(project.reload.import_error).not_to be_nil expect(import_state.reload.last_error).not_to be_nil
end end
end end
...@@ -90,8 +91,8 @@ ...@@ -90,8 +91,8 @@
.to receive(:async?) .to receive(:async?)
.and_return(true) .and_return(true)
expect_any_instance_of(Project) expect_any_instance_of(ProjectImportState)
.not_to receive(:import_finish) .not_to receive(:finish)
subject.perform(project.id) subject.perform(project.id)
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