diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-06 18:10:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-06 18:10:17 +0300 |
commit | 0a5ea888dca19dec6ce473a88c35a4ef95f61a9c (patch) | |
tree | 6507f8bd191ebe9f1e73e0d76c36b226f18c595f /spec | |
parent | 25db9c1230f7b54a7337b3d2dfe714478a7d54f0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/blob_controller_spec.rb | 90 | ||||
-rw-r--r-- | spec/features/projects/files/gitlab_ci_syntax_yml_dropdown_spec.rb | 70 | ||||
-rw-r--r-- | spec/finders/template_finder_spec.rb | 3 | ||||
-rw-r--r-- | spec/frontend/pipeline_editor/components/pipeline_editor_tabs_spec.js | 101 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/syntax_templates_spec.rb | 26 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/template/gitlab_ci_syntax_yml_template_spec.rb | 17 | ||||
-rw-r--r-- | spec/requests/api/project_templates_spec.rb | 17 | ||||
-rw-r--r-- | spec/services/ci/create_pipeline_service_spec.rb | 8 | ||||
-rw-r--r-- | spec/services/ci/register_job_service_spec.rb | 88 | ||||
-rw-r--r-- | spec/spec_helper.rb | 3 |
11 files changed, 117 insertions, 316 deletions
diff --git a/spec/controllers/projects/blob_controller_spec.rb b/spec/controllers/projects/blob_controller_spec.rb index c9a76049e19..4bc2a235eec 100644 --- a/spec/controllers/projects/blob_controller_spec.rb +++ b/spec/controllers/projects/blob_controller_spec.rb @@ -7,96 +7,6 @@ RSpec.describe Projects::BlobController do let(:project) { create(:project, :public, :repository) } - describe "GET new" do - context 'with no jobs' do - let_it_be(:user) { create(:user) } - let_it_be(:file_name) { '.gitlab-ci.yml' } - - def request - get(:new, params: { namespace_id: project.namespace, project_id: project, id: 'master', file_name: file_name } ) - end - - before do - project.add_maintainer(user) - sign_in(user) - - stub_experiment(ci_syntax_templates_b: experiment_active) - stub_experiment_for_subject(ci_syntax_templates_b: in_experiment_group) - end - - context 'when the experiment is not active' do - let(:experiment_active) { false } - let(:in_experiment_group) { false } - - it 'does not record the experiment user' do - expect(Experiment).not_to receive(:add_user) - - request - end - end - - context 'when the experiment is active' do - let(:experiment_active) { true } - - context 'when the user is in the control group' do - let(:in_experiment_group) { false } - - it 'records the experiment user in the control group' do - expect(Experiment).to receive(:add_user) - .with(:ci_syntax_templates_b, :control, user, namespace_id: project.namespace_id) - - request - end - end - - context 'when the user is in the experimental group' do - let(:in_experiment_group) { true } - - it 'records the experiment user in the experimental group' do - expect(Experiment).to receive(:add_user) - .with(:ci_syntax_templates_b, :experimental, user, namespace_id: project.namespace_id) - - request - end - - context 'when requesting a non default config file type' do - let(:file_name) { '.non_default_ci_config' } - let(:project) { create(:project, :public, :repository, ci_config_path: file_name) } - - it 'records the experiment user in the experimental group' do - expect(Experiment).to receive(:add_user) - .with(:ci_syntax_templates_b, :experimental, user, namespace_id: project.namespace_id) - - request - end - end - - context 'when requesting a different file type' do - let(:file_name) { '.gitignore' } - - it 'does not record the experiment user' do - expect(Experiment).not_to receive(:add_user) - - request - end - end - - context 'when the group is created longer than 90 days ago' do - before do - project.namespace.update_attribute(:created_at, 91.days.ago) - end - - it 'does not record the experiment user' do - expect(Experiment).not_to receive(:add_user) - - request - end - end - end - end - end - end - describe "GET show" do def request get(:show, params: { namespace_id: project.namespace, project_id: project, id: id }) diff --git a/spec/features/projects/files/gitlab_ci_syntax_yml_dropdown_spec.rb b/spec/features/projects/files/gitlab_ci_syntax_yml_dropdown_spec.rb deleted file mode 100644 index 10041825f0d..00000000000 --- a/spec/features/projects/files/gitlab_ci_syntax_yml_dropdown_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'Projects > Files > User wants to add a .gitlab-ci.yml file' do - include Spec::Support::Helpers::Features::EditorLiteSpecHelpers - - let_it_be(:namespace) { create(:namespace) } - - let(:project) { create(:project, :repository, namespace: namespace) } - - before do - sign_in project.owner - stub_experiment(ci_syntax_templates_b: experiment_active) - stub_experiment_for_subject(ci_syntax_templates_b: in_experiment_group) - - visit project_new_blob_path(project, 'master', file_name: '.gitlab-ci.yml') - end - - context 'when experiment is not active' do - let(:experiment_active) { false } - let(:in_experiment_group) { false } - - it 'does not show the "Learn CI/CD syntax" template dropdown' do - expect(page).not_to have_css('.gitlab-ci-syntax-yml-selector') - end - end - - context 'when experiment is active' do - let(:experiment_active) { true } - - context 'when the user is in the control group' do - let(:in_experiment_group) { false } - - it 'does not show the "Learn CI/CD syntax" template dropdown' do - expect(page).not_to have_css('.gitlab-ci-syntax-yml-selector') - end - end - - context 'when the user is in the experimental group' do - let(:in_experiment_group) { true } - - it 'allows the user to pick a "Learn CI/CD syntax" template from the dropdown', :js do - expect(page).to have_css('.gitlab-ci-syntax-yml-selector') - - find('.js-gitlab-ci-syntax-yml-selector').click - - wait_for_requests - - within '.gitlab-ci-syntax-yml-selector' do - find('.dropdown-input-field').set('Artifacts example') - find('.dropdown-content .is-focused', text: 'Artifacts example').click - end - - wait_for_requests - - expect(page).to have_css('.gitlab-ci-syntax-yml-selector .dropdown-toggle-text', text: 'Learn CI/CD syntax') - expect(editor_get_value).to have_content('You can use artifacts to pass data to jobs in later stages.') - end - - context 'when the group is created longer than 90 days ago' do - let(:namespace) { create(:namespace, created_at: 91.days.ago) } - - it 'does not show the "Learn CI/CD syntax" template dropdown' do - expect(page).not_to have_css('.gitlab-ci-syntax-yml-selector') - end - end - end - end -end diff --git a/spec/finders/template_finder_spec.rb b/spec/finders/template_finder_spec.rb index 164975fdfb6..b7339288c51 100644 --- a/spec/finders/template_finder_spec.rb +++ b/spec/finders/template_finder_spec.rb @@ -21,7 +21,6 @@ RSpec.describe TemplateFinder do :gitignores | 'Actionscript' :gitlab_ci_ymls | 'Android' :metrics_dashboard_ymls | 'Default' - :gitlab_ci_syntax_ymls | 'Artifacts example' end with_them do @@ -110,7 +109,6 @@ RSpec.describe TemplateFinder do :gitlab_ci_ymls | described_class :licenses | ::LicenseTemplateFinder :metrics_dashboard_ymls | described_class - :gitlab_ci_syntax_ymls | described_class :issues | described_class :merge_requests | described_class end @@ -160,7 +158,6 @@ RSpec.describe TemplateFinder do :gitignores | 'Actionscript' :gitlab_ci_ymls | 'Android' :metrics_dashboard_ymls | 'Default' - :gitlab_ci_syntax_ymls | 'Artifacts example' end with_them do diff --git a/spec/frontend/pipeline_editor/components/pipeline_editor_tabs_spec.js b/spec/frontend/pipeline_editor/components/pipeline_editor_tabs_spec.js index d4f467cc9e6..5cf8d47bc23 100644 --- a/spec/frontend/pipeline_editor/components/pipeline_editor_tabs_spec.js +++ b/spec/frontend/pipeline_editor/components/pipeline_editor_tabs_spec.js @@ -20,11 +20,6 @@ describe('Pipeline editor tabs component', () => { const MockTextEditor = { template: '<div />', }; - const mockProvide = { - glFeatures: { - ciConfigMergedTab: true, - }, - }; const createComponent = ({ props = {}, @@ -43,7 +38,7 @@ describe('Pipeline editor tabs component', () => { appStatus, }; }, - provide: { ...mockProvide, ...provide }, + provide: { ...provide }, stubs: { TextEditor: MockTextEditor, EditorTab, @@ -81,26 +76,24 @@ describe('Pipeline editor tabs component', () => { }); describe('visualization tab', () => { - describe('with feature flag on', () => { - describe('while loading', () => { - beforeEach(() => { - createComponent({ appStatus: EDITOR_APP_STATUS_LOADING }); - }); - - it('displays a loading icon if the lint query is loading', () => { - expect(findLoadingIcon().exists()).toBe(true); - expect(findPipelineGraph().exists()).toBe(false); - }); - }); - describe('after loading', () => { - beforeEach(() => { - createComponent(); - }); - - it('display the tab and visualization', () => { - expect(findVisualizationTab().exists()).toBe(true); - expect(findPipelineGraph().exists()).toBe(true); - }); + describe('while loading', () => { + beforeEach(() => { + createComponent({ appStatus: EDITOR_APP_STATUS_LOADING }); + }); + + it('displays a loading icon if the lint query is loading', () => { + expect(findLoadingIcon().exists()).toBe(true); + expect(findPipelineGraph().exists()).toBe(false); + }); + }); + describe('after loading', () => { + beforeEach(() => { + createComponent(); + }); + + it('display the tab and visualization', () => { + expect(findVisualizationTab().exists()).toBe(true); + expect(findPipelineGraph().exists()).toBe(true); }); }); }); @@ -132,51 +125,39 @@ describe('Pipeline editor tabs component', () => { }); describe('merged tab', () => { - describe('with feature flag on', () => { - describe('while loading', () => { - beforeEach(() => { - createComponent({ appStatus: EDITOR_APP_STATUS_LOADING }); - }); - - it('displays a loading icon if the lint query is loading', () => { - expect(findLoadingIcon().exists()).toBe(true); - }); + describe('while loading', () => { + beforeEach(() => { + createComponent({ appStatus: EDITOR_APP_STATUS_LOADING }); }); - describe('when there is a fetch error', () => { - beforeEach(() => { - createComponent({ appStatus: EDITOR_APP_STATUS_ERROR }); - }); - - it('show an error message', () => { - expect(findAlert().exists()).toBe(true); - expect(findAlert().text()).toBe(wrapper.vm.$options.errorTexts.loadMergedYaml); - }); + it('displays a loading icon if the lint query is loading', () => { + expect(findLoadingIcon().exists()).toBe(true); + }); + }); - it('does not render the `meged_preview` component', () => { - expect(findMergedPreview().exists()).toBe(false); - }); + describe('when there is a fetch error', () => { + beforeEach(() => { + createComponent({ appStatus: EDITOR_APP_STATUS_ERROR }); }); - describe('after loading', () => { - beforeEach(() => { - createComponent(); - }); + it('show an error message', () => { + expect(findAlert().exists()).toBe(true); + expect(findAlert().text()).toBe(wrapper.vm.$options.errorTexts.loadMergedYaml); + }); - it('display the tab and the merged preview component', () => { - expect(findMergedTab().exists()).toBe(true); - expect(findMergedPreview().exists()).toBe(true); - }); + it('does not render the `merged_preview` component', () => { + expect(findMergedPreview().exists()).toBe(false); }); }); - describe('with feature flag off', () => { + + describe('after loading', () => { beforeEach(() => { - createComponent({ provide: { glFeatures: { ciConfigMergedTab: false } } }); + createComponent(); }); - it('does not display the merged tab', () => { - expect(findMergedTab().exists()).toBe(false); - expect(findMergedPreview().exists()).toBe(false); + it('display the tab and the merged preview component', () => { + expect(findMergedTab().exists()).toBe(true); + expect(findMergedPreview().exists()).toBe(true); }); }); }); diff --git a/spec/lib/gitlab/ci/syntax_templates_spec.rb b/spec/lib/gitlab/ci/syntax_templates_spec.rb deleted file mode 100644 index 29a0ffe2f02..00000000000 --- a/spec/lib/gitlab/ci/syntax_templates_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'ci/syntax_templates' do - let_it_be(:project) { create(:project, :repository) } - let_it_be(:user) { create(:user) } - - let(:lint) { Gitlab::Ci::Lint.new(project: project, current_user: user) } - - before do - project.add_developer(user) - end - - subject(:lint_result) { lint.validate(content) } - - Dir.glob('lib/gitlab/ci/syntax_templates/**/*.yml').each do |template| - describe template do - let(:content) { File.read(template) } - - it 'validates the template' do - expect(lint_result).to be_valid, "got errors: #{lint_result.errors.join(', ')}" - end - end - end -end diff --git a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb index 43df16c710f..731c509e221 100644 --- a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb +++ b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb @@ -293,6 +293,16 @@ RSpec.describe Gitlab::SidekiqLogging::StructuredLogger do end end end + + context 'when instrumentation data is not loaded' do + before do + allow(logger).to receive(:info) + end + + it 'does not raise exception' do + expect { subject.call(job.dup, 'test_queue') {} }.not_to raise_error + end + end end describe '#add_time_keys!' do diff --git a/spec/lib/gitlab/template/gitlab_ci_syntax_yml_template_spec.rb b/spec/lib/gitlab/template/gitlab_ci_syntax_yml_template_spec.rb deleted file mode 100644 index d1024019a9f..00000000000 --- a/spec/lib/gitlab/template/gitlab_ci_syntax_yml_template_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Template::GitlabCiSyntaxYmlTemplate do - subject { described_class } - - describe '#content' do - it 'loads the full file' do - template = subject.new(Rails.root.join('lib/gitlab/ci/syntax_templates/Artifacts example.gitlab-ci.yml')) - - expect(template.content).to start_with('#') - end - end - - it_behaves_like 'file template shared examples', 'Artifacts example', '.gitlab-ci.yml' -end diff --git a/spec/requests/api/project_templates_spec.rb b/spec/requests/api/project_templates_spec.rb index a424bc62014..070fd6db3dc 100644 --- a/spec/requests/api/project_templates_spec.rb +++ b/spec/requests/api/project_templates_spec.rb @@ -53,15 +53,6 @@ RSpec.describe API::ProjectTemplates do expect(json_response).to satisfy_one { |template| template['key'] == 'Android' } end - it 'returns gitlab_ci_syntax_ymls' do - get api("/projects/#{public_project.id}/templates/gitlab_ci_syntax_ymls") - - expect(response).to have_gitlab_http_status(:ok) - expect(response).to include_pagination_headers - expect(response).to match_response_schema('public_api/v4/template_list') - expect(json_response).to satisfy_one { |template| template['key'] == 'Artifacts example' } - end - it 'returns licenses' do get api("/projects/#{public_project.id}/templates/licenses") @@ -172,14 +163,6 @@ RSpec.describe API::ProjectTemplates do expect(json_response['name']).to eq('Android') end - it 'returns a specific gitlab_ci_syntax_yml' do - get api("/projects/#{public_project.id}/templates/gitlab_ci_syntax_ymls/Artifacts%20example") - - expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('public_api/v4/template') - expect(json_response['name']).to eq('Artifacts example') - end - it 'returns a specific metrics_dashboard_yml' do get api("/projects/#{public_project.id}/templates/metrics_dashboard_ymls/Default") diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 4e4ece0d0f9..3ae4dc9f988 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -102,14 +102,6 @@ RSpec.describe Ci::CreatePipelineService do execute_service end - describe 'recording a conversion event' do - it 'schedules a record conversion event worker' do - expect(Experiments::RecordConversionEventWorker).to receive(:perform_async).with(:ci_syntax_templates_b, user.id) - - pipeline - end - end - context 'when merge requests already exist for this source branch' do let(:merge_request_1) do create(:merge_request, source_branch: 'feature', target_branch: "master", source_project: project) diff --git a/spec/services/ci/register_job_service_spec.rb b/spec/services/ci/register_job_service_spec.rb index fb2474ef63b..65211632e3a 100644 --- a/spec/services/ci/register_job_service_spec.rb +++ b/spec/services/ci/register_job_service_spec.rb @@ -82,31 +82,69 @@ module Ci let!(:build2_project2) { FactoryBot.create :ci_build, pipeline: pipeline2 } let!(:build1_project3) { FactoryBot.create :ci_build, pipeline: pipeline3 } - it 'prefers projects without builds first' do - # it gets for one build from each of the projects - expect(execute(shared_runner)).to eq(build1_project1) - expect(execute(shared_runner)).to eq(build1_project2) - expect(execute(shared_runner)).to eq(build1_project3) - - # then it gets a second build from each of the projects - expect(execute(shared_runner)).to eq(build2_project1) - expect(execute(shared_runner)).to eq(build2_project2) - - # in the end the third build - expect(execute(shared_runner)).to eq(build3_project1) - end - - it 'equalises number of running builds' do - # after finishing the first build for project 1, get a second build from the same project - expect(execute(shared_runner)).to eq(build1_project1) - build1_project1.reload.success - expect(execute(shared_runner)).to eq(build2_project1) - - expect(execute(shared_runner)).to eq(build1_project2) - build1_project2.reload.success - expect(execute(shared_runner)).to eq(build2_project2) - expect(execute(shared_runner)).to eq(build1_project3) - expect(execute(shared_runner)).to eq(build3_project1) + context 'when using fair scheduling' do + context 'when all builds are pending' do + it 'prefers projects without builds first' do + # it gets for one build from each of the projects + expect(execute(shared_runner)).to eq(build1_project1) + expect(execute(shared_runner)).to eq(build1_project2) + expect(execute(shared_runner)).to eq(build1_project3) + + # then it gets a second build from each of the projects + expect(execute(shared_runner)).to eq(build2_project1) + expect(execute(shared_runner)).to eq(build2_project2) + + # in the end the third build + expect(execute(shared_runner)).to eq(build3_project1) + end + end + + context 'when some builds transition to success' do + it 'equalises number of running builds' do + # after finishing the first build for project 1, get a second build from the same project + expect(execute(shared_runner)).to eq(build1_project1) + build1_project1.reload.success + expect(execute(shared_runner)).to eq(build2_project1) + + expect(execute(shared_runner)).to eq(build1_project2) + build1_project2.reload.success + expect(execute(shared_runner)).to eq(build2_project2) + expect(execute(shared_runner)).to eq(build1_project3) + expect(execute(shared_runner)).to eq(build3_project1) + end + end + end + + context 'when using DEFCON mode that disables fair scheduling' do + before do + stub_feature_flags(ci_queueing_disaster_recovery: true) + end + + context 'when all builds are pending' do + it 'returns builds in order of creation (FIFO)' do + # it gets for one build from each of the projects + expect(execute(shared_runner)).to eq(build1_project1) + expect(execute(shared_runner)).to eq(build2_project1) + expect(execute(shared_runner)).to eq(build3_project1) + expect(execute(shared_runner)).to eq(build1_project2) + expect(execute(shared_runner)).to eq(build2_project2) + expect(execute(shared_runner)).to eq(build1_project3) + end + end + + context 'when some builds transition to success' do + it 'returns builds in order of creation (FIFO)' do + expect(execute(shared_runner)).to eq(build1_project1) + build1_project1.reload.success + expect(execute(shared_runner)).to eq(build2_project1) + + expect(execute(shared_runner)).to eq(build3_project1) + build2_project1.reload.success + expect(execute(shared_runner)).to eq(build1_project2) + expect(execute(shared_runner)).to eq(build2_project2) + expect(execute(shared_runner)).to eq(build1_project3) + end + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4a3227cc9f5..34f9d189d71 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -253,6 +253,9 @@ RSpec.configure do |config| # tests, until we introduce it in user settings stub_feature_flags(forti_token_cloud: false) + # This feature flag is by default disabled and used in disaster recovery mode + stub_feature_flags(ci_queueing_disaster_recovery: false) + enable_rugged = example.metadata[:enable_rugged].present? # Disable Rugged features by default |