diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-14 11:41:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-14 11:41:52 +0300 |
commit | 585826cb22ecea5998a2c2a4675735c94bdeedac (patch) | |
tree | 5b05f0b30d33cef48963609e8a18a4dff260eab3 /spec/lib/gitlab/github_import | |
parent | df221d036e5d0c6c0ee4d55b9c97f481ee05dee8 (diff) |
Add latest changes from gitlab-org/gitlab@16-6-stable-eev16.6.0-rc42
Diffstat (limited to 'spec/lib/gitlab/github_import')
18 files changed, 237 insertions, 51 deletions
diff --git a/spec/lib/gitlab/github_import/attachments_downloader_spec.rb b/spec/lib/gitlab/github_import/attachments_downloader_spec.rb index 72d8a9c0403..65c5a7daeb2 100644 --- a/spec/lib/gitlab/github_import/attachments_downloader_spec.rb +++ b/spec/lib/gitlab/github_import/attachments_downloader_spec.rb @@ -94,9 +94,9 @@ RSpec.describe Gitlab::GithubImport::AttachmentsDownloader, feature_category: :i end end - context 'when attachment is behind a redirect' do - let_it_be(:file_url) { "https://github.com/test/project/assets/142635249/4b9f9c90-f060-4845-97cf-b24c558bcb11" } - let(:redirect_url) { "https://https://github-production-user-asset-6210df.s3.amazonaws.com/142635249/740edb05293e.jpg" } + context 'when attachment is behind a github asset endpoint' do + let(:file_url) { "https://github.com/test/project/assets/142635249/4b9f9c90-f060-4845-97cf-b24c558bcb11" } + let(:redirect_url) { "https://github-production-user-asset-6210df.s3.amazonaws.com/142635249/740edb05293e.jpg" } let(:sample_response) do instance_double(HTTParty::Response, redirection?: true, headers: { location: redirect_url }) end @@ -115,6 +115,8 @@ RSpec.describe Gitlab::GithubImport::AttachmentsDownloader, feature_category: :i end context 'when url is not a redirection' do + let(:file_url) { "https://github.com/test/project/assets/142635249/4b9f9c90-f060-4845-97cf-b24c558bcb11.jpg" } + let(:sample_response) do instance_double(HTTParty::Response, code: 200, redirection?: false) end @@ -125,8 +127,13 @@ RSpec.describe Gitlab::GithubImport::AttachmentsDownloader, feature_category: :i .and_return sample_response end - it 'raises upon unsuccessful redirection' do - expect { downloader.perform }.to raise_error("expected a redirect response, got #{sample_response.code}") + it 'queries with original file_url' do + expect(Gitlab::HTTP).to receive(:perform_request) + .with(Net::HTTP::Get, file_url, stream_body: true).and_yield(chunk_double) + + file = downloader.perform + + expect(File.exist?(file.path)).to eq(true) end end diff --git a/spec/lib/gitlab/github_import/client_spec.rb b/spec/lib/gitlab/github_import/client_spec.rb index 5f321a15de9..c409ec6983f 100644 --- a/spec/lib/gitlab/github_import/client_spec.rb +++ b/spec/lib/gitlab/github_import/client_spec.rb @@ -278,7 +278,7 @@ RSpec.describe Gitlab::GithubImport::Client, feature_category: :importers do client.with_rate_limit do if retries == 0 retries += 1 - raise(Octokit::TooManyRequests) + raise(Octokit::TooManyRequests.new(body: 'primary')) end end @@ -306,6 +306,37 @@ RSpec.describe Gitlab::GithubImport::Client, feature_category: :importers do expect(client.with_rate_limit { 10 }).to eq(10) end + context 'when threshold is hit' do + it 'raises a RateLimitError with the appropriate message' do + expect(client).to receive(:requests_remaining?).and_return(false) + + expect { client.with_rate_limit } + .to raise_error(Gitlab::GithubImport::RateLimitError, 'Internal threshold reached') + end + end + + context 'when primary rate limit hit' do + let(:limited_block) { -> { raise(Octokit::TooManyRequests.new(body: 'primary')) } } + + it 're-raises a RateLimitError with the appropriate message' do + expect(client).to receive(:requests_remaining?).and_return(true) + + expect { client.with_rate_limit(&limited_block) } + .to raise_error(Gitlab::GithubImport::RateLimitError, 'primary') + end + end + + context 'when secondary rate limit hit' do + let(:limited_block) { -> { raise(Octokit::TooManyRequests.new(body: 'secondary')) } } + + it 're-raises a RateLimitError with the appropriate message' do + expect(client).to receive(:requests_remaining?).and_return(true) + + expect { client.with_rate_limit(&limited_block) } + .to raise_error(Gitlab::GithubImport::RateLimitError, 'secondary') + end + end + context 'when Faraday error received from octokit', :aggregate_failures do let(:error_class) { described_class::CLIENT_CONNECTION_ERROR } let(:info_params) { { 'error.class': error_class } } @@ -392,7 +423,7 @@ RSpec.describe Gitlab::GithubImport::Client, feature_category: :importers do describe '#raise_or_wait_for_rate_limit' do context 'when running in parallel mode' do it 'raises RateLimitError' do - expect { client.raise_or_wait_for_rate_limit } + expect { client.raise_or_wait_for_rate_limit('primary') } .to raise_error(Gitlab::GithubImport::RateLimitError) end end @@ -404,7 +435,7 @@ RSpec.describe Gitlab::GithubImport::Client, feature_category: :importers do expect(client).to receive(:rate_limit_resets_in).and_return(1) expect(client).to receive(:sleep).with(1) - client.raise_or_wait_for_rate_limit + client.raise_or_wait_for_rate_limit('primary') end it 'increments the rate limit counter' do @@ -420,7 +451,7 @@ RSpec.describe Gitlab::GithubImport::Client, feature_category: :importers do .to receive(:increment) .and_call_original - client.raise_or_wait_for_rate_limit + client.raise_or_wait_for_rate_limit('primary') end end end diff --git a/spec/lib/gitlab/github_import/importer/collaborators_importer_spec.rb b/spec/lib/gitlab/github_import/importer/collaborators_importer_spec.rb index dcb02f32a28..6f602531d23 100644 --- a/spec/lib/gitlab/github_import/importer/collaborators_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/collaborators_importer_spec.rb @@ -82,7 +82,7 @@ RSpec.describe Gitlab::GithubImport::Importer::CollaboratorsImporter, feature_ca it 'imports each collaborator in parallel' do expect(Gitlab::GithubImport::ImportCollaboratorWorker).to receive(:perform_in) - .with(1.second, project.id, an_instance_of(Hash), an_instance_of(String)) + .with(1, project.id, an_instance_of(Hash), an_instance_of(String)) waiter = importer.parallel_import diff --git a/spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb index 945b742b025..4e8066ecb69 100644 --- a/spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb @@ -98,7 +98,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNotesImporter, feature_catego .and_yield(github_comment) expect(Gitlab::GithubImport::ImportDiffNoteWorker).to receive(:perform_in) - .with(1.second, project.id, an_instance_of(Hash), an_instance_of(String)) + .with(1, project.id, an_instance_of(Hash), an_instance_of(String)) waiter = importer.parallel_import diff --git a/spec/lib/gitlab/github_import/importer/issue_events_importer_spec.rb b/spec/lib/gitlab/github_import/importer/issue_events_importer_spec.rb index 04b694dc0cb..9aba6a2b02c 100644 --- a/spec/lib/gitlab/github_import/importer/issue_events_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/issue_events_importer_spec.rb @@ -78,7 +78,7 @@ RSpec.describe Gitlab::GithubImport::Importer::IssueEventsImporter, feature_cate allow(importer).to receive(:each_object_to_import).and_yield(issue_event) expect(Gitlab::GithubImport::ImportIssueEventWorker).to receive(:perform_in).with( - 1.second, project.id, an_instance_of(Hash), an_instance_of(String) + 1, project.id, an_instance_of(Hash), an_instance_of(String) ) waiter = importer.parallel_import diff --git a/spec/lib/gitlab/github_import/importer/issues_importer_spec.rb b/spec/lib/gitlab/github_import/importer/issues_importer_spec.rb index d6fd1a4739c..1bfdce04187 100644 --- a/spec/lib/gitlab/github_import/importer/issues_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/issues_importer_spec.rb @@ -92,7 +92,7 @@ RSpec.describe Gitlab::GithubImport::Importer::IssuesImporter, feature_category: expect(Gitlab::GithubImport::ImportIssueWorker) .to receive(:perform_in) - .with(1.second, project.id, an_instance_of(Hash), an_instance_of(String)) + .with(1, project.id, an_instance_of(Hash), an_instance_of(String)) waiter = importer.parallel_import diff --git a/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb b/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb index fab9d26532d..3f5ee68d264 100644 --- a/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb @@ -119,7 +119,7 @@ RSpec.describe Gitlab::GithubImport::Importer::LfsObjectsImporter, feature_categ end expect(Gitlab::GithubImport::ImportLfsObjectWorker).to receive(:perform_in) - .with(1.second, project.id, an_instance_of(Hash), an_instance_of(String)) + .with(1, project.id, an_instance_of(Hash), an_instance_of(String)) waiter = importer.parallel_import diff --git a/spec/lib/gitlab/github_import/importer/note_importer_spec.rb b/spec/lib/gitlab/github_import/importer/note_importer_spec.rb index 91311a8e90f..b5fe8c207c8 100644 --- a/spec/lib/gitlab/github_import/importer/note_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/note_importer_spec.rb @@ -99,7 +99,7 @@ RSpec.describe Gitlab::GithubImport::Importer::NoteImporter, feature_category: : end context 'when the note have invalid chars' do - let(:note_body) { %{There were an invalid char "\u0000" <= right here} } + let(:note_body) { %(There were an invalid char "\u0000" <= right here) } it 'removes invalid chars' do expect(importer.user_finder) diff --git a/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb index 841cc8178ea..8c93963f325 100644 --- a/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb @@ -84,7 +84,7 @@ RSpec.describe Gitlab::GithubImport::Importer::NotesImporter, feature_category: .and_yield(github_comment) expect(Gitlab::GithubImport::ImportNoteWorker).to receive(:perform_in) - .with(1.second, project.id, an_instance_of(Hash), an_instance_of(String)) + .with(1, project.id, an_instance_of(Hash), an_instance_of(String)) waiter = importer.parallel_import diff --git a/spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb b/spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb index 6a8b14a2690..8e99585109b 100644 --- a/spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb @@ -144,7 +144,7 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchesImporter, featur it 'imports each protected branch in parallel' do expect(Gitlab::GithubImport::ImportProtectedBranchWorker) .to receive(:perform_in) - .with(1.second, project.id, an_instance_of(Hash), an_instance_of(String)) + .with(1, project.id, an_instance_of(Hash), an_instance_of(String)) expect(Gitlab::GithubImport::ObjectCounter) .to receive(:increment).with(project, :protected_branch, :fetched) diff --git a/spec/lib/gitlab/github_import/importer/pull_requests/review_requests_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests/review_requests_importer_spec.rb index d0145ba1120..1977815e3a0 100644 --- a/spec/lib/gitlab/github_import/importer/pull_requests/review_requests_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/pull_requests/review_requests_importer_spec.rb @@ -97,7 +97,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequests::ReviewRequestsImpor { id: 4, login: 'alice' }, { id: 5, login: 'bob' } ] - }, + }.deep_stringify_keys, instance_of(String) ], [ @@ -108,7 +108,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequests::ReviewRequestsImpor users: [ { id: 4, login: 'alice' } ] - }, + }.deep_stringify_keys, instance_of(String) ] ] @@ -116,10 +116,10 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequests::ReviewRequestsImpor it 'schedule import for each merge request reviewers' do expect(Gitlab::GithubImport::PullRequests::ImportReviewRequestWorker) - .to receive(:perform_in).with(1.second, *expected_worker_payload.first) + .to receive(:perform_in).with(1, *expected_worker_payload.first) expect(Gitlab::GithubImport::PullRequests::ImportReviewRequestWorker) - .to receive(:perform_in).with(1.second, *expected_worker_payload.second) + .to receive(:perform_in).with(1, *expected_worker_payload.second) expect(Gitlab::GithubImport::ObjectCounter) .to receive(:increment).twice.with(project, :pull_request_review_request, :fetched) @@ -137,7 +137,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequests::ReviewRequestsImpor it "doesn't schedule import this merge request reviewers" do expect(Gitlab::GithubImport::PullRequests::ImportReviewRequestWorker) - .to receive(:perform_in).with(1.second, *expected_worker_payload.second) + .to receive(:perform_in).with(1, *expected_worker_payload.second) expect(Gitlab::GithubImport::ObjectCounter) .to receive(:increment).once.with(project, :pull_request_review_request, :fetched) diff --git a/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb index cfd75fba849..10e413fdfe5 100644 --- a/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb @@ -102,7 +102,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsImporter, feature_cat expect(Gitlab::GithubImport::ImportPullRequestWorker) .to receive(:perform_in) - .with(1.second, project.id, an_instance_of(Hash), an_instance_of(String)) + .with(1, project.id, an_instance_of(Hash), an_instance_of(String)) waiter = importer.parallel_import diff --git a/spec/lib/gitlab/github_import/issuable_finder_spec.rb b/spec/lib/gitlab/github_import/issuable_finder_spec.rb index d3236994cef..977fef95d64 100644 --- a/spec/lib/gitlab/github_import/issuable_finder_spec.rb +++ b/spec/lib/gitlab/github_import/issuable_finder_spec.rb @@ -2,40 +2,80 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::IssuableFinder, :clean_gitlab_redis_cache do - let(:project) { double(:project, id: 4, import_data: import_data) } +RSpec.describe Gitlab::GithubImport::IssuableFinder, :clean_gitlab_redis_cache, feature_category: :importers do + let(:project) { build(:project, id: 20, import_data_attributes: import_data_attributes) } let(:single_endpoint_optional_stage) { false } - let(:import_data) do - instance_double( - ProjectImportData, + let(:import_data_attributes) do + { data: { optional_stages: { single_endpoint_notes_import: single_endpoint_optional_stage } - }.deep_stringify_keys - ) + } + } end - let(:issue) { double(:issue, issuable_type: MergeRequest, issuable_id: 1) } + let(:merge_request) { create(:merge_request, source_project: project) } + let(:issue) { double(:issue, issuable_type: 'MergeRequest', issuable_id: merge_request.iid) } let(:finder) { described_class.new(project, issue) } describe '#database_id' do - it 'returns nil when no cache is in place' do - expect(finder.database_id).to be_nil + it 'returns nil if object does not exist' do + missing_issue = double(:issue, issuable_type: 'MergeRequest', issuable_id: 999) + + expect(described_class.new(project, missing_issue).database_id).to be_nil + end + + it 'fetches object id from database if not in cache' do + expect(finder.database_id).to eq(merge_request.id) end - it 'returns the ID of an issuable when the cache is in place' do + it 'fetches object id from cache if present' do finder.cache_database_id(10) expect(finder.database_id).to eq(10) end + it 'returns nil and skips database read if cache has no record' do + finder.cache_database_id(-1) + + expect(finder.database_id).to be_nil + end + it 'raises TypeError when the object is not supported' do finder = described_class.new(project, double(:issue)) expect { finder.database_id }.to raise_error(TypeError) end + context 'with FF import_fallback_to_db_empty_cache disabled' do + before do + stub_feature_flags(import_fallback_to_db_empty_cache: false) + end + + it 'returns nil if object does not exist' do + missing_issue = double(:issue, issuable_type: 'MergeRequest', issuable_id: 999) + + expect(described_class.new(project, missing_issue).database_id).to be_nil + end + + it 'does not fetch object id from database if not in cache' do + expect(finder.database_id).to eq(nil) + end + + it 'fetches object id from cache if present' do + finder.cache_database_id(10) + + expect(finder.database_id).to eq(10) + end + + it 'returns -1 if cache is -1' do + finder.cache_database_id(-1) + + expect(finder.database_id).to eq(-1) + end + end + context 'when group is present' do context 'when settings single_endpoint_notes_import is enabled' do let(:single_endpoint_optional_stage) { true } @@ -65,7 +105,7 @@ RSpec.describe Gitlab::GithubImport::IssuableFinder, :clean_gitlab_redis_cache d it 'caches the ID of a database row' do expect(Gitlab::Cache::Import::Caching) .to receive(:write) - .with('github-import/issuable-finder/4/MergeRequest/1', 10, timeout: 86400) + .with("github-import/issuable-finder/20/MergeRequest/#{merge_request.iid}", 10, timeout: 86400) finder.cache_database_id(10) end diff --git a/spec/lib/gitlab/github_import/label_finder_spec.rb b/spec/lib/gitlab/github_import/label_finder_spec.rb index 9905fce2a20..e46595974d1 100644 --- a/spec/lib/gitlab/github_import/label_finder_spec.rb +++ b/spec/lib/gitlab/github_import/label_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::LabelFinder, :clean_gitlab_redis_cache do +RSpec.describe Gitlab::GithubImport::LabelFinder, :clean_gitlab_redis_cache, feature_category: :importers do let_it_be(:project) { create(:project) } let_it_be(:finder) { described_class.new(project) } let_it_be(:bug) { create(:label, project: project, name: 'Bug') } @@ -18,23 +18,64 @@ RSpec.describe Gitlab::GithubImport::LabelFinder, :clean_gitlab_redis_cache do expect(finder.id_for(feature.name)).to eq(feature.id) end - it 'returns nil for an empty cache key' do + it 'fetches object id from database if not in cache' do key = finder.cache_key_for(bug.name) Gitlab::Cache::Import::Caching.write(key, '') - expect(finder.id_for(bug.name)).to be_nil + expect(finder.id_for(bug.name)).to eq(bug.id) end it 'returns nil for a non existing label name' do expect(finder.id_for('kittens')).to be_nil end + + it 'returns nil and skips database read if cache has no record' do + key = finder.cache_key_for(bug.name) + + Gitlab::Cache::Import::Caching.write(key, -1) + + expect(finder.id_for(bug.name)).to be_nil + end end context 'without a cache in place' do - it 'returns nil for a label' do + it 'caches the ID of a database row and returns the ID' do + expect(Gitlab::Cache::Import::Caching) + .to receive(:write) + .with("github-import/label-finder/#{project.id}/#{feature.name}", feature.id) + .and_call_original + + expect(finder.id_for(feature.name)).to eq(feature.id) + end + end + + context 'with FF import_fallback_to_db_empty_cache disabled' do + before do + stub_feature_flags(import_fallback_to_db_empty_cache: false) + end + + it 'returns nil for a non existing label name' do + expect(finder.id_for('kittens')).to be_nil + end + + it 'does not fetch object id from database if not in cache' do expect(finder.id_for(feature.name)).to be_nil end + + it 'fetches object id from cache if present' do + finder.build_cache + + expect(finder.id_for(feature.name)).to eq(feature.id) + end + + it 'returns -1 if cache is -1' do + key = finder.cache_key_for(bug.name) + + Gitlab::Cache::Import::Caching.write(key, -1) + + expect(finder.id_for(bug.name)).to eq(-1) + end end end diff --git a/spec/lib/gitlab/github_import/milestone_finder_spec.rb b/spec/lib/gitlab/github_import/milestone_finder_spec.rb index e7f47d334e8..62886981de1 100644 --- a/spec/lib/gitlab/github_import/milestone_finder_spec.rb +++ b/spec/lib/gitlab/github_import/milestone_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::MilestoneFinder, :clean_gitlab_redis_cache do +RSpec.describe Gitlab::GithubImport::MilestoneFinder, :clean_gitlab_redis_cache, feature_category: :importers do let_it_be(:project) { create(:project) } let_it_be(:milestone) { create(:milestone, project: project) } @@ -20,23 +20,72 @@ RSpec.describe Gitlab::GithubImport::MilestoneFinder, :clean_gitlab_redis_cache expect(finder.id_for(issuable)).to eq(milestone.id) end - it 'returns nil for an empty cache key' do + it 'returns nil if object does not exist' do + missing_issuable = double(:issuable, milestone_number: 999) + + expect(finder.id_for(missing_issuable)).to be_nil + end + + it 'fetches object id from database if not in cache' do key = finder.cache_key_for(milestone.iid) Gitlab::Cache::Import::Caching.write(key, '') - expect(finder.id_for(issuable)).to be_nil + expect(finder.id_for(issuable)).to eq(milestone.id) end it 'returns nil for an issuable with a non-existing milestone' do expect(finder.id_for(double(:issuable, milestone_number: 5))).to be_nil end + + it 'returns nil and skips database read if cache has no record' do + key = finder.cache_key_for(milestone.iid) + + Gitlab::Cache::Import::Caching.write(key, -1) + + expect(finder.id_for(issuable)).to be_nil + end end context 'without a cache in place' do - it 'returns nil' do + it 'caches the ID of a database row and returns the ID' do + expect(Gitlab::Cache::Import::Caching) + .to receive(:write) + .with("github-import/milestone-finder/#{project.id}/1", milestone.id) + .and_call_original + + expect(finder.id_for(issuable)).to eq(milestone.id) + end + end + + context 'with FF import_fallback_to_db_empty_cache disabled' do + before do + stub_feature_flags(import_fallback_to_db_empty_cache: false) + end + + it 'returns nil if object does not exist' do + missing_issuable = double(:issuable, milestone_number: 999) + + expect(finder.id_for(missing_issuable)).to be_nil + end + + it 'does not fetch object id from database if not in cache' do expect(finder.id_for(issuable)).to be_nil end + + it 'fetches object id from cache if present' do + finder.build_cache + + expect(finder.id_for(issuable)).to eq(milestone.id) + end + + it 'returns -1 if cache is -1' do + key = finder.cache_key_for(milestone.iid) + + Gitlab::Cache::Import::Caching.write(key, -1) + + expect(finder.id_for(issuable)).to eq(-1) + end end end diff --git a/spec/lib/gitlab/github_import/object_counter_spec.rb b/spec/lib/gitlab/github_import/object_counter_spec.rb index e41a2cff989..964bdd6aad1 100644 --- a/spec/lib/gitlab/github_import/object_counter_spec.rb +++ b/spec/lib/gitlab/github_import/object_counter_spec.rb @@ -68,6 +68,16 @@ RSpec.describe Gitlab::GithubImport::ObjectCounter, :clean_gitlab_redis_cache, f 'imported' => { 'issue' => 8 } ) end + + it 'uses the same TTL as when incrementing' do + expect(Gitlab::Cache::Import::Caching) + .to receive(:read_integer) + .with(anything, timeout: described_class::IMPORT_CACHING_TIMEOUT) + .twice + .and_call_original + + described_class.summary(project) + end end context 'when import is in progress but cache expired' do diff --git a/spec/lib/gitlab/github_import/parallel_scheduling_spec.rb b/spec/lib/gitlab/github_import/parallel_scheduling_spec.rb index 9de39a3ff7e..e0b1ff1bc33 100644 --- a/spec/lib/gitlab/github_import/parallel_scheduling_spec.rb +++ b/spec/lib/gitlab/github_import/parallel_scheduling_spec.rb @@ -296,11 +296,11 @@ RSpec.describe Gitlab::GithubImport::ParallelScheduling, feature_category: :impo expect(importer).to receive(:each_object_to_import) .and_yield(object).and_yield(object).and_yield(object) expect(worker_class).to receive(:perform_in) - .with(1.second, project.id, { title: 'One' }, 'waiter-key').ordered + .with(1, project.id, { 'title' => 'One' }, 'waiter-key').ordered expect(worker_class).to receive(:perform_in) - .with(1.second, project.id, { title: 'Two' }, 'waiter-key').ordered + .with(1, project.id, { 'title' => 'Two' }, 'waiter-key').ordered expect(worker_class).to receive(:perform_in) - .with(1.minute + 1.second, project.id, { title: 'Three' }, 'waiter-key').ordered + .with(61, project.id, { 'title' => 'Three' }, 'waiter-key').ordered job_waiter = importer.parallel_import @@ -325,11 +325,11 @@ RSpec.describe Gitlab::GithubImport::ParallelScheduling, feature_category: :impo expect(importer).to receive(:each_object_to_import).and_yield(object).and_yield(object).and_yield(object) expect(worker_class).to receive(:perform_in) - .with(1.second, project.id, { title: 'One' }, 'waiter-key').ordered + .with(1, project.id, { 'title' => 'One' }, 'waiter-key').ordered expect(worker_class).to receive(:perform_in) - .with(1.minute + 1.second, project.id, { title: 'Two' }, 'waiter-key').ordered + .with(61, project.id, { 'title' => 'Two' }, 'waiter-key').ordered expect(worker_class).to receive(:perform_in) - .with(2.minutes + 1.second, project.id, { title: 'Three' }, 'waiter-key').ordered + .with(121, project.id, { 'title' => 'Three' }, 'waiter-key').ordered job_waiter = importer.parallel_import diff --git a/spec/lib/gitlab/github_import/representation/to_hash_spec.rb b/spec/lib/gitlab/github_import/representation/to_hash_spec.rb index 739c832025c..52edffe586d 100644 --- a/spec/lib/gitlab/github_import/representation/to_hash_spec.rb +++ b/spec/lib/gitlab/github_import/representation/to_hash_spec.rb @@ -2,14 +2,14 @@ require 'fast_spec_helper' -RSpec.describe Gitlab::GithubImport::Representation::ToHash do +RSpec.describe Gitlab::GithubImport::Representation::ToHash, feature_category: :importers do describe '#to_hash' do let(:user) { double(:user, attributes: { login: 'alice' }) } let(:issue) do double( :issue, - attributes: { user: user, assignees: [user], number: 42 } + attributes: { user: user, assignees: [user], number: 42, created_at: 5.days.ago, status: :valid } ) end @@ -35,5 +35,13 @@ RSpec.describe Gitlab::GithubImport::Representation::ToHash do it 'keeps values as-is if they do not respond to #to_hash' do expect(issue_hash[:number]).to eq(42) end + + it 'converts Date value to String' do + expect(issue_hash[:created_at]).to be_an_instance_of(String) + end + + it 'converts Symbol value to String' do + expect(issue_hash[:status]).to be_an_instance_of(String) + end end end |