Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-24 03:12:33 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-24 03:12:33 +0300
commit1c27dcaf69cd0181755172d94c87c823e4d5f069 (patch)
tree4cf0f9084d3c3878bd31aed8a3f3c2bec0b8da0f /spec/lib
parentabd24a801e8dbe0942558dd2b2cad90e7e01938e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/bulk_imports/ndjson_pipeline_spec.rb16
-rw-r--r--spec/lib/gitlab/database/background_migration/batched_job_spec.rb12
-rw-r--r--spec/lib/gitlab/database/background_migration/batched_migration_spec.rb22
3 files changed, 46 insertions, 4 deletions
diff --git a/spec/lib/bulk_imports/ndjson_pipeline_spec.rb b/spec/lib/bulk_imports/ndjson_pipeline_spec.rb
index cb6f80a06a6..8ea6ceb7619 100644
--- a/spec/lib/bulk_imports/ndjson_pipeline_spec.rb
+++ b/spec/lib/bulk_imports/ndjson_pipeline_spec.rb
@@ -130,6 +130,22 @@ RSpec.describe BulkImports::NdjsonPipeline do
subject.transform(context, data)
end
+
+ context 'when data is nil' do
+ before do
+ expect(Gitlab::ImportExport::Group::RelationFactory).not_to receive(:create)
+ end
+
+ it 'returns' do
+ expect(subject.transform(nil, nil)).to be_nil
+ end
+
+ context 'when relation hash is nil' do
+ it 'returns' do
+ expect(subject.transform(nil, [nil, 0])).to be_nil
+ end
+ end
+ end
end
describe '#load' do
diff --git a/spec/lib/gitlab/database/background_migration/batched_job_spec.rb b/spec/lib/gitlab/database/background_migration/batched_job_spec.rb
index 0182e0f7651..c4364826ee2 100644
--- a/spec/lib/gitlab/database/background_migration/batched_job_spec.rb
+++ b/spec/lib/gitlab/database/background_migration/batched_job_spec.rb
@@ -17,15 +17,19 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedJob, type: :model d
let_it_be(:stuck_job) { create(:batched_background_migration_job, status: :pending, updated_at: fixed_time - described_class::STUCK_JOBS_TIMEOUT) }
let_it_be(:failed_job) { create(:batched_background_migration_job, status: :failed, attempts: 1) }
- before_all do
- create(:batched_background_migration_job, status: :failed, attempts: described_class::MAX_ATTEMPTS)
- create(:batched_background_migration_job, status: :succeeded)
- end
+ let!(:max_attempts_failed_job) { create(:batched_background_migration_job, status: :failed, attempts: described_class::MAX_ATTEMPTS) }
+ let!(:succeeded_job) { create(:batched_background_migration_job, status: :succeeded) }
before do
travel_to fixed_time
end
+ describe '.except_succeeded' do
+ it 'returns not succeeded jobs' do
+ expect(described_class.except_succeeded).to contain_exactly(pending_job, running_job, stuck_job, failed_job, max_attempts_failed_job)
+ end
+ end
+
describe '.active' do
it 'returns active jobs' do
expect(described_class.active).to contain_exactly(pending_job, running_job, stuck_job)
diff --git a/spec/lib/gitlab/database/background_migration/batched_migration_spec.rb b/spec/lib/gitlab/database/background_migration/batched_migration_spec.rb
index a1c2634f59c..961a92cc6bc 100644
--- a/spec/lib/gitlab/database/background_migration/batched_migration_spec.rb
+++ b/spec/lib/gitlab/database/background_migration/batched_migration_spec.rb
@@ -23,6 +23,28 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigration, type: :m
subject { build(:batched_background_migration) }
it { is_expected.to validate_uniqueness_of(:job_arguments).scoped_to(:job_class_name, :table_name, :column_name) }
+
+ context 'when there are failed jobs' do
+ let(:batched_migration) { create(:batched_background_migration, status: :active, total_tuple_count: 100) }
+ let!(:batched_job) { create(:batched_background_migration_job, batched_migration: batched_migration, status: :failed) }
+
+ it 'raises an exception' do
+ expect { batched_migration.finished! }.to raise_error(ActiveRecord::RecordInvalid)
+
+ expect(batched_migration.reload.status).to eql 'active'
+ end
+ end
+
+ context 'when the jobs are completed' do
+ let(:batched_migration) { create(:batched_background_migration, status: :active, total_tuple_count: 100) }
+ let!(:batched_job) { create(:batched_background_migration_job, batched_migration: batched_migration, status: :succeeded) }
+
+ it 'finishes the migration' do
+ batched_migration.finished!
+
+ expect(batched_migration.status).to eql 'finished'
+ end
+ end
end
describe '.queue_order' do