diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-25 18:09:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-25 18:09:02 +0300 |
commit | d1c0c1c4c3241eae6795562d8a0c22def6771238 (patch) | |
tree | 676e20b1bbee71a6a78b95dd517f0ffa7e684f96 /spec/services | |
parent | fc4faf47ac4e5f1ddc40640c42c32405c38c9455 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/merge_requests/after_create_service_spec.rb | 25 | ||||
-rw-r--r-- | spec/services/object_storage/delete_stale_direct_uploads_service_spec.rb | 108 |
2 files changed, 133 insertions, 0 deletions
diff --git a/spec/services/merge_requests/after_create_service_spec.rb b/spec/services/merge_requests/after_create_service_spec.rb index 50a3d49d4a3..7255d19ef8a 100644 --- a/spec/services/merge_requests/after_create_service_spec.rb +++ b/spec/services/merge_requests/after_create_service_spec.rb @@ -231,5 +231,30 @@ RSpec.describe MergeRequests::AfterCreateService, feature_category: :code_review expect(service).to have_received(:execute).with(merge_request) end + + describe 'logging' do + it 'logs specific events' do + ::Gitlab::ApplicationContext.push(caller_id: 'NewMergeRequestWorker') + + allow(Gitlab::AppLogger).to receive(:info).and_call_original + + [ + 'Executing hooks', + 'Executed hooks', + 'Creating pipeline', + 'Pipeline created' + ].each do |message| + expect(Gitlab::AppLogger).to receive(:info).with( + hash_including( + 'meta.caller_id' => 'NewMergeRequestWorker', + message: message, + merge_request_id: merge_request.id + ) + ).and_call_original + end + + execute_service + end + end end end diff --git a/spec/services/object_storage/delete_stale_direct_uploads_service_spec.rb b/spec/services/object_storage/delete_stale_direct_uploads_service_spec.rb new file mode 100644 index 00000000000..e44d57e9bb5 --- /dev/null +++ b/spec/services/object_storage/delete_stale_direct_uploads_service_spec.rb @@ -0,0 +1,108 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ObjectStorage::DeleteStaleDirectUploadsService, :direct_uploads, :clean_gitlab_redis_shared_state, feature_category: :shared do + let(:service) { described_class.new } + + describe '#execute', :aggregate_failures do + subject(:execute_result) { service.execute } + + let(:location_identifier) { JobArtifactUploader.storage_location_identifier } + let(:fog_connection) { stub_artifacts_object_storage(JobArtifactUploader, direct_upload: true) } + + let(:stale_path_1) { 'stale/path/123' } + let!(:stale_object_1) do + fog_connection.directories + .new(key: location_identifier.to_s) + .files + .create( # rubocop:disable Rails/SaveBang + key: stale_path_1, + body: 'something' + ) + end + + let(:stale_path_2) { 'stale/path/456' } + let!(:stale_object_2) do + fog_connection.directories + .new(key: location_identifier.to_s) + .files + .create( # rubocop:disable Rails/SaveBang + key: stale_path_2, + body: 'something' + ) + end + + let(:non_stale_path) { 'nonstale/path/123' } + let!(:non_stale_object) do + fog_connection.directories + .new(key: location_identifier.to_s) + .files + .create( # rubocop:disable Rails/SaveBang + key: non_stale_path, + body: 'something' + ) + end + + it 'only deletes stale entries', :aggregate_failures do + prepare_pending_direct_upload(stale_path_1, 5.hours.ago) + prepare_pending_direct_upload(stale_path_2, 4.hours.ago) + prepare_pending_direct_upload(non_stale_path, 3.minutes.ago) + + expect(execute_result).to eq( + status: :success, + total_pending_entries: 3, + total_deleted_stale_entries: 2, + execution_timeout: false + ) + + expect_not_to_have_pending_direct_upload(stale_path_1) + expect_pending_uploaded_object_not_to_exist(stale_path_1) + + expect_not_to_have_pending_direct_upload(stale_path_2) + expect_pending_uploaded_object_not_to_exist(stale_path_2) + + expect_to_have_pending_direct_upload(non_stale_path) + expect_pending_uploaded_object_to_exist(non_stale_path) + end + + context 'when a stale entry does not have a matching object in the storage' do + it 'does not fail and still remove the stale entry' do + stale_no_object_path = 'some/other/path' + prepare_pending_direct_upload(stale_path_1, 5.hours.ago) + prepare_pending_direct_upload(stale_no_object_path, 5.hours.ago) + + expect(execute_result[:status]).to eq(:success) + + expect_not_to_have_pending_direct_upload(stale_path_1) + expect_pending_uploaded_object_not_to_exist(stale_path_1) + + expect_not_to_have_pending_direct_upload(stale_no_object_path) + end + end + + context 'when timeout happens' do + before do + stub_const("#{described_class}::MAX_EXEC_DURATION", 0.seconds) + + prepare_pending_direct_upload(stale_path_1, 5.hours.ago) + prepare_pending_direct_upload(stale_path_2, 4.hours.ago) + end + + it 'completes the current iteration and reports information about total entries' do + expect(execute_result).to eq( + status: :success, + total_pending_entries: 2, + total_deleted_stale_entries: 1, + execution_timeout: true + ) + + expect_not_to_have_pending_direct_upload(stale_path_1) + expect_pending_uploaded_object_not_to_exist(stale_path_1) + + expect_to_have_pending_direct_upload(stale_path_2) + expect_pending_uploaded_object_to_exist(stale_path_2) + end + end + end +end |