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 @@
end
it 'is not scheduled' do
expect(project.import_scheduled?).to be(false)
expect(project.import_scheduled?).to be_nil
end
it 'repository is empty' do
......
......@@ -58,14 +58,16 @@
end
describe '#find_project' do
let(:import_state) { create(:import_state, project: project) }
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)
end
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
end
......
......@@ -28,13 +28,23 @@
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
it 'logs the appropriate error message for forked projects' do
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
......@@ -17,8 +17,8 @@
context 'when there are remaining jobs' do
before do
allow(worker)
.to receive(:find_project)
.and_return(project)
.to receive(:find_import_state)
.and_return(import_state)
end
it 'reschedules itself' do
......@@ -38,8 +38,8 @@
context 'when there are no remaining jobs' do
before do
allow(worker)
.to receive(:find_project)
.and_return(project)
.to receive(:find_import_state)
.and_return(import_state)
allow(worker)
.to receive(:wait_for_jobs)
......@@ -48,8 +48,8 @@
end
it 'schedules the next stage' do
expect(project)
.to receive(:refresh_import_jid_expiration)
expect(import_state)
.to receive(:refresh_jid_expiration)
expect(Gitlab::GithubImport::Stage::FinishImportWorker)
.to receive(:perform_async)
......@@ -96,22 +96,18 @@
end
end
describe '#find_project' do
it 'returns a Project' do
project.update_column(:import_status, 'started')
describe '#find_import_state' do
it 'returns a ProjectImportState' do
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)
# 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' })
expect(found).to be_an_instance_of(ProjectImportState)
expect(found.attributes.keys).to match_array(%w(id jid))
end
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
......@@ -29,7 +29,7 @@
context 'when the job is running' do
it 'refreshes the import JID and reschedules itself' do
allow(worker)
.to receive(:find_project)
.to receive(:find_import_state)
.with(project.id)
.and_return(project)
......@@ -39,7 +39,7 @@
.and_return(true)
expect(project)
.to receive(:refresh_import_jid_expiration)
.to receive(:refresh_jid_expiration)
expect(worker.class)
.to receive(:perform_in_the_future)
......@@ -52,7 +52,7 @@
context 'when the job is no longer running' do
it 'returns' do
allow(worker)
.to receive(:find_project)
.to receive(:find_import_state)
.with(project.id)
.and_return(project)
......@@ -62,18 +62,18 @@
.and_return(false)
expect(project)
.not_to receive(:refresh_import_jid_expiration)
.not_to receive(:refresh_jid_expiration)
worker.perform(project.id, '123')
end
end
end
describe '#find_project' do
it 'returns a Project' do
describe '#find_import_state' do
it 'returns a ProjectImportState' do
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
# it 'only selects the import JID field' do
......@@ -84,14 +84,14 @@
# .to eq({ 'id' => nil, 'import_jid' => '123abc' })
# 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)
expect(worker.find_project(project.id)).to be_nil
expect(worker.find_import_state(project.id)).to be_nil
end
it 'returns nil for a non-existing project' do
expect(worker.find_project(-1)).to be_nil
it 'returns nil for a non-existing find_import_state' do
expect(worker.find_import_state(-1)).to be_nil
end
end
end
......@@ -2,6 +2,7 @@
describe Gitlab::GithubImport::Stage::ImportBaseDataWorker do
let(:project) { create(:project) }
let(:import_state) { create(:import_state, project: project) }
let(:worker) { described_class.new }
describe '#import' do
......@@ -18,7 +19,7 @@
expect(importer).to receive(:execute)
end
expect(project).to receive(:refresh_import_jid_expiration)
expect(import_state).to receive(:refresh_jid_expiration)
expect(Gitlab::GithubImport::Stage::ImportPullRequestsWorker)
.to receive(:perform_async)
......
......@@ -2,6 +2,7 @@
describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do
let(:project) { create(:project) }
let(:import_state) { create(:import_state, project: project) }
let(:worker) { described_class.new }
describe '#import' do
......@@ -19,8 +20,8 @@
.to receive(:execute)
.and_return(waiter)
expect(project)
.to receive(:refresh_import_jid_expiration)
expect(import_state)
.to receive(:refresh_jid_expiration)
expect(Gitlab::GithubImport::AdvanceStageWorker)
.to receive(:perform_async)
......
......@@ -9,13 +9,13 @@
describe '#perform' do
let(:project) { create(:project, :import_scheduled) }
let(:import_state) { project.import_state }
context 'when worker was reset without cleanup' do
it 'imports the project successfully' do
jid = '12345678'
started_project = create(:project)
create(:import_state, :started, project: started_project, jid: jid)
started_import_state = create(:import_state, :started, project: started_project, jid: jid)
allow(subject).to receive(:jid).and_return(jid)
......@@ -23,12 +23,12 @@
.and_return({ status: :ok })
# Works around https://github.com/rspec/rspec-mocks/issues/910
expect(Project).to receive(:find).with(project.id).and_return(project)
expect(project.repository).to receive(:expire_emptiness_caches)
expect(project.wiki.repository).to receive(:expire_emptiness_caches)
expect(project).to receive(:import_finish)
expect(Project).to receive(:find).with(started_project.id).and_return(started_project)
expect(started_project.repository).to receive(:expire_emptiness_caches)
expect(started_project.wiki.repository).to receive(:expire_emptiness_caches)
expect(started_import_state).to receive(:finish)
subject.perform(project.id)
subject.perform(started_project.id)
end
end
......@@ -41,7 +41,7 @@
expect(Project).to receive(:find).with(project.id).and_return(project)
expect(project.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)
end
......@@ -51,26 +51,27 @@
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 }
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 do
subject.perform(project.id)
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
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 }
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 do
subject.perform(project.id)
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
......@@ -90,8 +91,8 @@
.to receive(:async?)
.and_return(true)
expect_any_instance_of(Project)
.not_to receive(:import_finish)
expect_any_instance_of(ProjectImportState)
.not_to receive(:finish)
subject.perform(project.id)
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