diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-05 15:08:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-05 15:08:59 +0300 |
commit | f63850d9d6c3a81e78c93995c904ed6c0785ef19 (patch) | |
tree | 099eb28c2e54892f16f5cfe7b16119052676e724 /spec | |
parent | 0c5dab41b6baec548aaea06cb9b545c87b489678 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
10 files changed, 216 insertions, 88 deletions
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index 8ccbc0d3fe2..a943a5e0205 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -1894,15 +1894,12 @@ RSpec.describe Projects::MergeRequestsController do # First run to insert test data from lets, which does take up some 30 queries get_ci_environments_status - control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { get_ci_environments_status }.count + control_count = ActiveRecord::QueryRecorder.new { get_ci_environments_status } environment2 = create(:environment, project: forked) create(:deployment, :succeed, environment: environment2, sha: sha, ref: 'master', deployable: build) - # TODO address the last 3 queries - # See https://gitlab.com/gitlab-org/gitlab-foss/issues/63952 (3 queries) - leeway = 3 - expect { get_ci_environments_status }.not_to exceed_all_query_limit(control_count + leeway) + expect { get_ci_environments_status }.not_to exceed_all_query_limit(control_count) end end diff --git a/spec/features/projects/settings/registry_settings_spec.rb b/spec/features/projects/settings/registry_settings_spec.rb index 9468540736f..1fb46c669e7 100644 --- a/spec/features/projects/settings/registry_settings_spec.rb +++ b/spec/features/projects/settings/registry_settings_spec.rb @@ -31,7 +31,6 @@ RSpec.describe 'Project > Settings > Packages & Registries > Container registry subject within '[data-testid="container-expiration-policy-project-settings"]' do - click_button('Expand') select('Every day', from: 'Run cleanup') select('50 tags per image name', from: 'Keep the most recent:') fill_in('Keep tags matching:', with: 'stable') @@ -50,7 +49,6 @@ RSpec.describe 'Project > Settings > Packages & Registries > Container registry subject within '[data-testid="container-expiration-policy-project-settings"]' do - click_button('Expand') fill_in('Remove tags matching:', with: '*-production') submit_button = find('[data-testid="save-button"') @@ -76,7 +74,6 @@ RSpec.describe 'Project > Settings > Packages & Registries > Container registry subject within '[data-testid="container-expiration-policy-project-settings"]' do - click_button('Expand') expect(find('[data-testid="enable-toggle"]')).to have_content('Disabled - Tags will not be automatically deleted.') end end @@ -91,7 +88,6 @@ RSpec.describe 'Project > Settings > Packages & Registries > Container registry subject within '[data-testid="container-expiration-policy-project-settings"]' do - click_button('Expand') expect(find('.gl-alert-title')).to have_content('Cleanup policy for tags is disabled') end end diff --git a/spec/frontend/packages_and_registries/package_registry/components/details/__snapshots__/package_title_spec.js.snap b/spec/frontend/packages_and_registries/package_registry/components/details/__snapshots__/package_title_spec.js.snap index fdddc131412..61923233d2e 100644 --- a/spec/frontend/packages_and_registries/package_registry/components/details/__snapshots__/package_title_spec.js.snap +++ b/spec/frontend/packages_and_registries/package_registry/components/details/__snapshots__/package_title_spec.js.snap @@ -29,19 +29,25 @@ exports[`PackageTitle renders with tags 1`] = ` <div class="gl-display-flex gl-align-items-center gl-text-gray-500 gl-mt-3" > - <span + <div + class="gl-display-flex gl-gap-3" data-testid="sub-header" > v 1.0.0 published <time-ago-tooltip-stub - class="gl-ml-2" cssclass="" time="2020-08-17T14:23:32Z" tooltipplacement="top" /> - </span> + + <package-tags-stub + hidelabel="true" + tagdisplaylimit="2" + tags="[object Object],[object Object],[object Object]" + /> + </div> </div> </div> </div> @@ -73,15 +79,6 @@ exports[`PackageTitle renders with tags 1`] = ` texttooltip="" /> </div> - <div - class="gl-display-flex gl-align-items-center gl-mr-5" - > - <package-tags-stub - hidelabel="true" - tagdisplaylimit="2" - tags="[object Object],[object Object],[object Object]" - /> - </div> </div> </div> @@ -121,19 +118,21 @@ exports[`PackageTitle renders without tags 1`] = ` <div class="gl-display-flex gl-align-items-center gl-text-gray-500 gl-mt-3" > - <span + <div + class="gl-display-flex gl-gap-3" data-testid="sub-header" > v 1.0.0 published <time-ago-tooltip-stub - class="gl-ml-2" cssclass="" time="2020-08-17T14:23:32Z" tooltipplacement="top" /> - </span> + + <!----> + </div> </div> </div> </div> diff --git a/spec/frontend/packages_and_registries/settings/project/settings/components/__snapshots__/container_expiration_policy_form_spec.js.snap b/spec/frontend/packages_and_registries/settings/project/settings/components/__snapshots__/container_expiration_policy_form_spec.js.snap index 108d9478788..5d08574234c 100644 --- a/spec/frontend/packages_and_registries/settings/project/settings/components/__snapshots__/container_expiration_policy_form_spec.js.snap +++ b/spec/frontend/packages_and_registries/settings/project/settings/components/__snapshots__/container_expiration_policy_form_spec.js.snap @@ -5,6 +5,7 @@ exports[`Container Expiration Policy Settings Form Cadence matches snapshot 1`] class="gl-mr-7 gl-mb-0!" data-testid="cadence-dropdown" description="" + dropdownclass="" formoptions="[object Object],[object Object],[object Object],[object Object],[object Object]" label="Run cleanup:" name="cadence" @@ -24,6 +25,7 @@ exports[`Container Expiration Policy Settings Form Keep N matches snapshot 1`] = <expiration-dropdown-stub data-testid="keep-n-dropdown" description="" + dropdownclass="" formoptions="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]" label="Keep the most recent:" name="keep-n" @@ -47,6 +49,7 @@ exports[`Container Expiration Policy Settings Form OlderThan matches snapshot 1` <expiration-dropdown-stub data-testid="older-than-dropdown" description="" + dropdownclass="" formoptions="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]" label="Remove tags older than:" name="older-than" diff --git a/spec/lib/gitlab/tracking/destinations/snowplow_micro_spec.rb b/spec/lib/gitlab/tracking/destinations/snowplow_micro_spec.rb index 2554a15d97e..48092a33da3 100644 --- a/spec/lib/gitlab/tracking/destinations/snowplow_micro_spec.rb +++ b/spec/lib/gitlab/tracking/destinations/snowplow_micro_spec.rb @@ -48,40 +48,8 @@ RSpec.describe Gitlab::Tracking::Destinations::SnowplowMicro do allow(Gitlab.config).to receive(:snowplow_micro).and_raise(Settingslogic::MissingSetting) end - context 'when SNOWPLOW_MICRO_URI has scheme and port' do - before do - stub_env('SNOWPLOW_MICRO_URI', 'http://gdk.test:9091') - end - - it 'returns hostname URI part' do - expect(subject.hostname).to eq('gdk.test:9091') - end - end - - context 'when SNOWPLOW_MICRO_URI is without protocol' do - before do - stub_env('SNOWPLOW_MICRO_URI', 'gdk.test:9091') - end - - it 'returns hostname URI part' do - expect(subject.hostname).to eq('gdk.test:9091') - end - end - - context 'when SNOWPLOW_MICRO_URI is hostname only' do - before do - stub_env('SNOWPLOW_MICRO_URI', 'uriwithoutport') - end - - it 'returns hostname URI with default HTTP port' do - expect(subject.hostname).to eq('uriwithoutport:80') - end - end - - context 'when SNOWPLOW_MICRO_URI is not set' do - it 'returns localhost hostname' do - expect(subject.hostname).to eq('localhost:9090') - end + it 'returns localhost hostname' do + expect(subject.hostname).to eq('localhost:9090') end end end diff --git a/spec/lib/gitlab/tracking_spec.rb b/spec/lib/gitlab/tracking_spec.rb index 36ef1abcb50..028c985f3b3 100644 --- a/spec/lib/gitlab/tracking_spec.rb +++ b/spec/lib/gitlab/tracking_spec.rb @@ -90,15 +90,6 @@ RSpec.describe Gitlab::Tracking do it_behaves_like 'delegates to SnowplowMicro destination with proper options' end - - context "enabled with env variable" do - before do - allow(Gitlab.config).to receive(:snowplow_micro).and_raise(Settingslogic::MissingSetting) - stub_env('SNOWPLOW_MICRO_ENABLE', '1') - end - - it_behaves_like 'delegates to SnowplowMicro destination with proper options' - end end it 'when feature flag is disabled' do @@ -149,7 +140,6 @@ RSpec.describe Gitlab::Tracking do context 'when destination is Snowplow' do before do - stub_env('SNOWPLOW_MICRO_ENABLE', '0') allow(Rails.env).to receive(:development?).and_return(true) end @@ -158,7 +148,6 @@ RSpec.describe Gitlab::Tracking do context 'when destination is SnowplowMicro' do before do - stub_env('SNOWPLOW_MICRO_ENABLE', '1') allow(Rails.env).to receive(:development?).and_return(true) end @@ -212,4 +201,28 @@ RSpec.describe Gitlab::Tracking do project: project, user: user, namespace: namespace, extra_key_1: 'extra value 1') end end + + describe 'snowplow_micro_enabled?' do + before do + allow(Rails.env).to receive(:development?).and_return(true) + end + + it 'returns true when snowplow_micro is enabled' do + stub_config(snowplow_micro: { enabled: true }) + + expect(described_class).to be_snowplow_micro_enabled + end + + it 'returns false when snowplow_micro is disabled' do + stub_config(snowplow_micro: { enabled: false }) + + expect(described_class).not_to be_snowplow_micro_enabled + end + + it 'returns false when snowplow_micro is not configured' do + allow(Gitlab.config).to receive(:snowplow_micro).and_raise(Settingslogic::MissingSetting) + + expect(described_class).not_to be_snowplow_micro_enabled + end + end end diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index a822e613860..ae8748f8ae3 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -552,6 +552,10 @@ RSpec.describe Ci::Runner do allow_any_instance_of(described_class).to receive(:cached_attribute).and_call_original allow_any_instance_of(described_class).to receive(:cached_attribute) .with(:platform).and_return("darwin") + allow_any_instance_of(described_class).to receive(:cached_attribute) + .with(:version).and_return("14.0.0") + + allow(Ci::Runners::ProcessRunnerVersionUpdateWorker).to receive(:perform_async).once end context 'table tests' do @@ -623,6 +627,10 @@ RSpec.describe Ci::Runner do allow_any_instance_of(described_class).to receive(:cached_attribute).and_call_original allow_any_instance_of(described_class).to receive(:cached_attribute) .with(:platform).and_return("darwin") + allow_any_instance_of(described_class).to receive(:cached_attribute) + .with(:version).and_return("14.0.0") + + allow(Ci::Runners::ProcessRunnerVersionUpdateWorker).to receive(:perform_async).once end context 'no cache value' do @@ -693,19 +701,6 @@ RSpec.describe Ci::Runner do it { is_expected.to eq([runner1]) } end - describe '#tick_runner_queue' do - it 'sticks the runner to the primary and calls the original method' do - runner = create(:ci_runner) - - expect(described_class.sticking).to receive(:stick) - .with(:runner, runner.id) - - expect(Gitlab::Workhorse).to receive(:set_key_and_notify) - - runner.tick_runner_queue - end - end - describe '#matches_build?' do using RSpec::Parameterized::TableSyntax @@ -989,6 +984,16 @@ RSpec.describe Ci::Runner do it 'returns a new last_update value' do expect(runner.tick_runner_queue).not_to be_empty end + + it 'sticks the runner to the primary and calls the original method' do + runner = create(:ci_runner) + + expect(described_class.sticking).to receive(:stick).with(:runner, runner.id) + + expect(Gitlab::Workhorse).to receive(:set_key_and_notify) + + runner.tick_runner_queue + end end describe '#ensure_runner_queue_value' do @@ -1055,14 +1060,19 @@ RSpec.describe Ci::Runner do it 'updates cache' do expect_redis_update + expect(Ci::Runners::ProcessRunnerVersionUpdateWorker).not_to receive(:perform_async) heartbeat + + expect(runner.runner_version).to be_nil end end context 'when database was not updated recently' do before do runner.contacted_at = 2.hours.ago + + allow(Ci::Runners::ProcessRunnerVersionUpdateWorker).to receive(:perform_async) end context 'with invalid runner' do @@ -1075,12 +1085,25 @@ RSpec.describe Ci::Runner do expect_redis_update does_db_update + + expect(Ci::Runners::ProcessRunnerVersionUpdateWorker).to have_received(:perform_async).once + end + end + + context 'with unchanged runner version' do + let(:runner) { create(:ci_runner, version: version) } + + it 'does not schedule ci_runner_versions update' do + heartbeat + + expect(Ci::Runners::ProcessRunnerVersionUpdateWorker).not_to have_received(:perform_async) end end it 'updates redis cache and database' do expect_redis_update does_db_update + expect(Ci::Runners::ProcessRunnerVersionUpdateWorker).to have_received(:perform_async).once end %w(custom shell docker docker-windows docker-ssh ssh parallels virtualbox docker+machine docker-ssh+machine kubernetes some-unknown-type).each do |executor| diff --git a/spec/services/ci/runners/process_runner_version_update_service_spec.rb b/spec/services/ci/runners/process_runner_version_update_service_spec.rb new file mode 100644 index 00000000000..b885138fc7a --- /dev/null +++ b/spec/services/ci/runners/process_runner_version_update_service_spec.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::Runners::ProcessRunnerVersionUpdateService do + subject(:service) { described_class.new(version) } + + let(:version) { '1.0.0' } + let(:available_runner_releases) { %w[1.0.0 1.0.1] } + + describe '#execute' do + subject(:execute) { service.execute } + + context 'with upgrade check returning error' do + let(:service_double) { instance_double(Gitlab::Ci::RunnerUpgradeCheck) } + + before do + allow(service_double).to receive(:check_runner_upgrade_suggestion).with(version) + .and_return([version, :error]) + allow(service).to receive(:upgrade_check_service).and_return(service_double) + end + + it 'does not update ci_runner_versions records', :aggregate_failures do + expect do + expect(execute).to be_error + expect(execute.message).to eq 'upgrade version check failed' + end.not_to change(Ci::RunnerVersion, :count).from(0) + expect(service_double).to have_received(:check_runner_upgrade_suggestion).with(version).once + end + end + + context 'with successful result from upgrade check' do + before do + url = ::Gitlab::CurrentSettings.current_application_settings.public_runner_releases_url + + WebMock.stub_request(:get, url).to_return( + body: available_runner_releases.map { |v| { name: v } }.to_json, + status: 200, + headers: { 'Content-Type' => 'application/json' } + ) + end + + context 'with no existing ci_runner_version record' do + it 'creates ci_runner_versions record', :aggregate_failures do + expect do + expect(execute).to be_success + expect(execute.http_status).to eq :ok + expect(execute.payload).to eq({ upgrade_status: 'recommended' }) + end.to change(Ci::RunnerVersion, :all).to contain_exactly( + an_object_having_attributes(version: version, status: 'recommended') + ) + end + end + + context 'with existing ci_runner_version record' do + let!(:runner_version) { create(:ci_runner_version, version: '1.0.0', status: :not_available) } + + it 'updates ci_runner_versions record', :aggregate_failures do + expect do + expect(execute).to be_success + expect(execute.http_status).to eq :ok + expect(execute.payload).to eq({ upgrade_status: 'recommended' }) + end.to change { runner_version.reload.status }.from('not_available').to('recommended') + end + end + + context 'with up-to-date ci_runner_version record' do + let!(:runner_version) { create(:ci_runner_version, version: '1.0.0', status: :recommended) } + + it 'does not update ci_runner_versions record', :aggregate_failures do + expect do + expect(execute).to be_success + expect(execute.http_status).to eq :ok + expect(execute.payload).to eq({ upgrade_status: 'recommended' }) + end.not_to change { runner_version.reload.status } + end + end + end + end +end diff --git a/spec/services/ci/runners/reset_registration_token_service_spec.rb b/spec/services/ci/runners/reset_registration_token_service_spec.rb index c4bfff51cc8..f96838cea98 100644 --- a/spec/services/ci/runners/reset_registration_token_service_spec.rb +++ b/spec/services/ci/runners/reset_registration_token_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe ::Ci::Runners::ResetRegistrationTokenService, '#execute' do - subject { described_class.new(scope, current_user).execute } + subject(:execute) { described_class.new(scope, current_user).execute } let_it_be(:user) { build(:user) } let_it_be(:admin_user) { create(:user, :admin) } @@ -12,20 +12,20 @@ RSpec.describe ::Ci::Runners::ResetRegistrationTokenService, '#execute' do context 'without user' do let(:current_user) { nil } - it 'does not reset registration token and returns nil' do + it 'does not reset registration token and returns error response' do expect(scope).not_to receive(token_reset_method_name) - is_expected.to be_nil + is_expected.to be_error end end context 'with unauthorized user' do let(:current_user) { user } - it 'does not reset registration token and returns nil' do + it 'does not reset registration token and returns error response' do expect(scope).not_to receive(token_reset_method_name) - is_expected.to be_nil + is_expected.to be_error end end @@ -37,7 +37,8 @@ RSpec.describe ::Ci::Runners::ResetRegistrationTokenService, '#execute' do expect(scope).to receive(token_method_name).once.and_return("#{token_method_name} return value") end - is_expected.to eq("#{token_method_name} return value") + is_expected.to be_success + expect(execute.payload[:new_registration_token]).to eq("#{token_method_name} return value") end end end diff --git a/spec/workers/ci/runners/process_runner_version_update_worker_spec.rb b/spec/workers/ci/runners/process_runner_version_update_worker_spec.rb new file mode 100644 index 00000000000..ff67266c3e8 --- /dev/null +++ b/spec/workers/ci/runners/process_runner_version_update_worker_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::Runners::ProcessRunnerVersionUpdateWorker do + subject(:worker) { described_class.new } + + describe '#perform' do + let(:version) { '1.0.0' } + let(:job_args) { version } + + include_examples 'an idempotent worker' do + subject(:perform_twice) { perform_multiple(job_args, worker: worker, exec_times: 2) } + + let(:service) { ::Ci::Runners::ProcessRunnerVersionUpdateService.new(version) } + let(:available_runner_releases) do + %w[1.0.0 1.0.1] + end + + before do + allow(Ci::Runners::ProcessRunnerVersionUpdateService).to receive(:new).and_return(service) + allow(service).to receive(:execute).and_call_original + + url = ::Gitlab::CurrentSettings.current_application_settings.public_runner_releases_url + + WebMock.stub_request(:get, url).to_return( + body: available_runner_releases.map { |v| { name: v } }.to_json, + status: 200, + headers: { 'Content-Type' => 'application/json' } + ) + end + + it 'logs the service result', :aggregate_failures do + perform_twice + + expect(Ci::Runners::ProcessRunnerVersionUpdateService).to have_received(:new).twice + expect(service).to have_received(:execute).twice + expect(worker.logging_extras).to eq( + { + 'extra.ci_runners_process_runner_version_update_worker.status' => :success, + 'extra.ci_runners_process_runner_version_update_worker.message' => nil, + 'extra.ci_runners_process_runner_version_update_worker.upgrade_status' => 'recommended' + } + ) + end + end + end +end |