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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-20 15:08:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-20 15:08:50 +0300
commit81fb153d0550c2c0b707a374cb6ee9f2ad089790 (patch)
tree0326c005bea62adc258bb0d4d1a3a7f5fc6a9532 /spec
parent084d7453e0866f2b29923552fb1c5f380f283ab5 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/commits_spec.rb3
-rw-r--r--spec/features/issues/issue_detail_spec.rb10
-rw-r--r--spec/features/projects/pipelines/legacy_pipeline_spec.rb89
-rw-r--r--spec/features/projects/pipelines/pipeline_spec.rb8
-rw-r--r--spec/frontend/mr_popover/__snapshots__/mr_popover_spec.js.snap8
-rw-r--r--spec/frontend/pipelines/components/pipeline_tabs_spec.js26
-rw-r--r--spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js2
-rw-r--r--spec/frontend/vue_shared/issuable/show/components/issuable_header_spec.js4
-rw-r--r--spec/frontend/vue_shared/issuable/show/components/issuable_title_spec.js16
-rw-r--r--spec/helpers/projects/pipeline_helper_spec.rb4
-rw-r--r--spec/helpers/search_helper_spec.rb24
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/limit/rate_limit_spec.rb33
-rw-r--r--spec/models/ci/build_spec.rb22
-rw-r--r--spec/models/deployment_spec.rb113
-rw-r--r--spec/services/ci/create_pipeline_service/rate_limit_spec.rb5
-rw-r--r--spec/services/ci/create_pipeline_service_spec.rb4
-rw-r--r--spec/services/deployments/create_service_spec.rb37
-rw-r--r--spec/services/deployments/update_environment_service_spec.rb2
18 files changed, 304 insertions, 106 deletions
diff --git a/spec/features/commits_spec.rb b/spec/features/commits_spec.rb
index 4b38df175e2..db841ffc627 100644
--- a/spec/features/commits_spec.rb
+++ b/spec/features/commits_spec.rb
@@ -10,7 +10,6 @@ RSpec.describe 'Commits' do
before do
sign_in(user)
stub_ci_pipeline_to_return_yaml_file
- stub_feature_flags(pipeline_tabs_vue: false)
end
let(:creator) { create(:user, developer_projects: [project]) }
@@ -94,7 +93,6 @@ RSpec.describe 'Commits' do
context 'Download artifacts', :js do
before do
- stub_feature_flags(pipeline_tabs_vue: false)
create(:ci_job_artifact, :archive, file: artifacts_file, job: build)
end
@@ -124,7 +122,6 @@ RSpec.describe 'Commits' do
context "when logged as reporter", :js do
before do
- stub_feature_flags(pipeline_tabs_vue: false)
project.add_reporter(user)
create(:ci_job_artifact, :archive, file: artifacts_file, job: build)
visit builds_project_pipeline_path(project, pipeline)
diff --git a/spec/features/issues/issue_detail_spec.rb b/spec/features/issues/issue_detail_spec.rb
index 88709d66887..2af54e51bb7 100644
--- a/spec/features/issues/issue_detail_spec.rb
+++ b/spec/features/issues/issue_detail_spec.rb
@@ -140,13 +140,9 @@ RSpec.describe 'Issue Detail', :js do
end
context 'by non-member author' do
- it 'routes the user to the issue details page when the `issue_type` is set to issue' do
- open_issue_edit_form
-
- page.within('[data-testid="issuable-form"]') do
- update_type_select('Incident', 'Issue')
-
- expect(page).to have_current_path(project_issue_path(project, incident))
+ it 'cannot edit issuable' do
+ page.within('.content') do
+ expect(page).to have_no_button('Edit title and description')
end
end
end
diff --git a/spec/features/projects/pipelines/legacy_pipeline_spec.rb b/spec/features/projects/pipelines/legacy_pipeline_spec.rb
index a29cef393a8..203837fc5d4 100644
--- a/spec/features/projects/pipelines/legacy_pipeline_spec.rb
+++ b/spec/features/projects/pipelines/legacy_pipeline_spec.rb
@@ -1070,4 +1070,93 @@ RSpec.describe 'Pipeline', :js do
end
end
end
+
+ describe 'GET /:project/-/pipelines/:id/builds' do
+ include_context 'pipeline builds'
+
+ let_it_be(:project) { create(:project, :repository) }
+
+ let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id) }
+
+ before do
+ visit builds_project_pipeline_path(project, pipeline)
+ end
+
+ it 'shows a list of jobs' do
+ expect(page).to have_content('Test')
+ expect(page).to have_content(build_passed.id)
+ expect(page).to have_content('Deploy')
+ expect(page).to have_content(build_failed.id)
+ expect(page).to have_content(build_running.id)
+ expect(page).to have_content(build_external.id)
+ expect(page).to have_content('Retry')
+ expect(page).to have_content('Cancel running')
+ expect(page).to have_button('Play')
+ end
+
+ context 'page tabs' do
+ it 'shows Pipeline, Jobs and DAG tabs with link' do
+ expect(page).to have_link('Pipeline')
+ expect(page).to have_link('Jobs')
+ expect(page).to have_link('Needs')
+ end
+
+ it 'shows counter in Jobs tab' do
+ expect(page.find('.js-builds-counter').text).to eq(pipeline.total_size.to_s)
+ end
+ end
+
+ context 'retrying jobs' do
+ it { expect(page).not_to have_content('retried') }
+
+ context 'when retrying' do
+ before do
+ find('[data-testid="retry"]', match: :first).click
+ end
+
+ it 'does not show a "Retry" button', :sidekiq_might_not_need_inline do
+ expect(page).not_to have_content('Retry')
+ end
+ end
+ end
+
+ context 'canceling jobs' do
+ it { expect(page).not_to have_selector('.ci-canceled') }
+
+ context 'when canceling' do
+ before do
+ click_on 'Cancel running'
+ end
+
+ it 'does not show a "Cancel running" button', :sidekiq_might_not_need_inline do
+ expect(page).not_to have_content('Cancel running')
+ end
+ end
+ end
+
+ context 'playing manual job' do
+ before do
+ within '[data-testid="jobs-tab-table"]' do
+ click_button('Play')
+
+ wait_for_requests
+ end
+ end
+
+ it { expect(build_manual.reload).to be_pending }
+ end
+
+ context 'when user unschedules a delayed job' do
+ before do
+ within '[data-testid="jobs-tab-table"]' do
+ click_button('Unschedule')
+ end
+ end
+
+ it 'unschedules the delayed job and shows play button as a manual job' do
+ expect(page).to have_button('Play')
+ expect(page).not_to have_button('Unschedule')
+ end
+ end
+ end
end
diff --git a/spec/features/projects/pipelines/pipeline_spec.rb b/spec/features/projects/pipelines/pipeline_spec.rb
index 9eda05f695d..d3052bfa02b 100644
--- a/spec/features/projects/pipelines/pipeline_spec.rb
+++ b/spec/features/projects/pipelines/pipeline_spec.rb
@@ -508,8 +508,7 @@ RSpec.describe 'Pipeline', :js do
end
it 'shows counter in Jobs tab' do
- skip('Enable in jobs `pipeline_tabs_vue` MR')
- expect(page.find('.js-builds-counter').text).to eq(pipeline.total_size.to_s)
+ expect(page.find('[data-testid="builds-counter"]').text).to eq(pipeline.total_size.to_s)
end
context 'without permission to access builds' do
@@ -889,7 +888,6 @@ RSpec.describe 'Pipeline', :js do
describe 'GET /:project/-/pipelines/:id/builds' do
before do
- stub_feature_flags(pipeline_tabs_vue: false)
visit builds_project_pipeline_path(project, pipeline)
end
@@ -1042,7 +1040,6 @@ RSpec.describe 'Pipeline', :js do
let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id) }
before do
- stub_feature_flags(pipeline_tabs_vue: false)
visit builds_project_pipeline_path(project, pipeline)
end
@@ -1066,8 +1063,7 @@ RSpec.describe 'Pipeline', :js do
end
it 'shows counter in Jobs tab' do
- skip('unskip when jobs tab is implemented with ff `pipeline_tabs_vue`')
- expect(page.find('.js-builds-counter').text).to eq(pipeline.total_size.to_s)
+ expect(page.find('[data-testid="builds-counter"]').text).to eq(pipeline.total_size.to_s)
end
end
diff --git a/spec/frontend/mr_popover/__snapshots__/mr_popover_spec.js.snap b/spec/frontend/mr_popover/__snapshots__/mr_popover_spec.js.snap
index 5d84b4660c9..a03d8bf5bf4 100644
--- a/spec/frontend/mr_popover/__snapshots__/mr_popover_spec.js.snap
+++ b/spec/frontend/mr_popover/__snapshots__/mr_popover_spec.js.snap
@@ -17,13 +17,15 @@ exports[`MR Popover loaded state matches the snapshot 1`] = `
<div
class="d-inline-flex align-items-center"
>
- <div
- class="issuable-status-box status-box status-box-open"
+ <gl-badge-stub
+ class="gl-mr-3"
+ size="md"
+ variant="success"
>
Open
- </div>
+ </gl-badge-stub>
<span
class="gl-text-secondary"
diff --git a/spec/frontend/pipelines/components/pipeline_tabs_spec.js b/spec/frontend/pipelines/components/pipeline_tabs_spec.js
index 89002ee47a8..f2b188efea8 100644
--- a/spec/frontend/pipelines/components/pipeline_tabs_spec.js
+++ b/spec/frontend/pipelines/components/pipeline_tabs_spec.js
@@ -1,4 +1,5 @@
import { shallowMount } from '@vue/test-utils';
+import { GlTab } from '@gitlab/ui';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import PipelineTabs from '~/pipelines/components/pipeline_tabs.vue';
import PipelineGraphWrapper from '~/pipelines/components/graph/graph_component_wrapper.vue';
@@ -21,8 +22,11 @@ describe('The Pipeline Tabs', () => {
const findPipelineApp = () => wrapper.findComponent(PipelineGraphWrapper);
const findTestsApp = () => wrapper.findComponent(TestReports);
+ const findJobsBadge = () => wrapper.findByTestId('builds-counter');
+
const defaultProvide = {
defaultTabValue: '',
+ totalJobCount: 10,
};
const createComponent = (propsData = {}) => {
@@ -33,7 +37,7 @@ describe('The Pipeline Tabs', () => {
...defaultProvide,
},
stubs: {
- JobsApp: { template: '<div class="jobs" />' },
+ GlTab,
TestReports: { template: '<div id="tests" />' },
},
}),
@@ -58,9 +62,23 @@ describe('The Pipeline Tabs', () => {
${'Jobs'} | ${findJobsTab} | ${findJobsApp}
${'Failed Jobs'} | ${findFailedJobsTab} | ${findFailedJobsApp}
${'Tests'} | ${findTestsTab} | ${findTestsApp}
- `('shows $tabName tab and its associated component', ({ appComponent, tabComponent }) => {
- expect(tabComponent().exists()).toBe(true);
- expect(appComponent().exists()).toBe(true);
+ `(
+ 'shows $tabName tab with its badge and its associated component',
+ ({ appComponent, tabComponent }) => {
+ expect(tabComponent().exists()).toBe(true);
+ expect(appComponent().exists()).toBe(true);
+ },
+ );
+ });
+
+ // We are going to add more tabs tests here as we do each tab MR
+ describe('Tabs badges', () => {
+ it.each`
+ tabName | badgeComponent | badgeText
+ ${'Jobs'} | ${findJobsBadge} | ${String(defaultProvide.totalJobCount)}
+ `('shows badge for $tabName with the correct text', ({ badgeComponent, badgeText }) => {
+ expect(badgeComponent().exists()).toBe(true);
+ expect(badgeComponent().text()).toBe(badgeText);
});
});
});
diff --git a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js
index f03a2e7934f..51161a1a0ef 100644
--- a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js
+++ b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js
@@ -77,7 +77,7 @@ describe('LabelToken', () => {
describe('getActiveLabel', () => {
it('returns label object from labels array based on provided `currentValue` param', () => {
- expect(wrapper.vm.getActiveLabel(mockLabels, 'foo label')).toEqual(mockRegularLabel);
+ expect(wrapper.vm.getActiveLabel(mockLabels, 'Foo Label')).toEqual(mockRegularLabel);
});
});
diff --git a/spec/frontend/vue_shared/issuable/show/components/issuable_header_spec.js b/spec/frontend/vue_shared/issuable/show/components/issuable_header_spec.js
index 544db891a13..e00bb184535 100644
--- a/spec/frontend/vue_shared/issuable/show/components/issuable_header_spec.js
+++ b/spec/frontend/vue_shared/issuable/show/components/issuable_header_spec.js
@@ -1,4 +1,4 @@
-import { GlIcon, GlAvatarLabeled } from '@gitlab/ui';
+import { GlBadge, GlIcon, GlAvatarLabeled } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
import IssuableHeader from '~/vue_shared/issuable/show/components/issuable_header.vue';
@@ -69,7 +69,7 @@ describe('IssuableHeader', () => {
describe('template', () => {
it('renders issuable status icon and text', () => {
createComponent();
- const statusBoxEl = wrapper.findByTestId('status');
+ const statusBoxEl = wrapper.findComponent(GlBadge);
const statusIconEl = statusBoxEl.findComponent(GlIcon);
expect(statusBoxEl.exists()).toBe(true);
diff --git a/spec/frontend/vue_shared/issuable/show/components/issuable_title_spec.js b/spec/frontend/vue_shared/issuable/show/components/issuable_title_spec.js
index 11e3302d409..2e418ed3041 100644
--- a/spec/frontend/vue_shared/issuable/show/components/issuable_title_spec.js
+++ b/spec/frontend/vue_shared/issuable/show/components/issuable_title_spec.js
@@ -1,4 +1,4 @@
-import { GlIcon, GlButton, GlIntersectionObserver } from '@gitlab/ui';
+import { GlIcon, GlBadge, GlButton, GlIntersectionObserver } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
@@ -40,7 +40,7 @@ describe('IssuableTitle', () => {
describe('methods', () => {
describe('handleTitleAppear', () => {
it('sets value of `stickyTitleVisible` prop to false', () => {
- wrapper.find(GlIntersectionObserver).vm.$emit('appear');
+ wrapper.findComponent(GlIntersectionObserver).vm.$emit('appear');
expect(wrapper.vm.stickyTitleVisible).toBe(false);
});
@@ -48,7 +48,7 @@ describe('IssuableTitle', () => {
describe('handleTitleDisappear', () => {
it('sets value of `stickyTitleVisible` prop to true', () => {
- wrapper.find(GlIntersectionObserver).vm.$emit('disappear');
+ wrapper.findComponent(GlIntersectionObserver).vm.$emit('disappear');
expect(wrapper.vm.stickyTitleVisible).toBe(true);
});
@@ -77,7 +77,7 @@ describe('IssuableTitle', () => {
});
it('renders edit button', () => {
- const editButtonEl = wrapper.find(GlButton);
+ const editButtonEl = wrapper.findComponent(GlButton);
const tooltip = getBinding(editButtonEl.element, 'gl-tooltip');
expect(editButtonEl.exists()).toBe(true);
@@ -97,7 +97,13 @@ describe('IssuableTitle', () => {
const stickyHeaderEl = wrapper.find('[data-testid="header"]');
expect(stickyHeaderEl.exists()).toBe(true);
- expect(stickyHeaderEl.find(GlIcon).props('name')).toBe(issuableTitleProps.statusIcon);
+ expect(stickyHeaderEl.findComponent(GlBadge).props('variant')).toBe('success');
+ expect(stickyHeaderEl.findComponent(GlBadge).classes()).toContain(
+ mockIssuableShowProps.statusBadgeClass,
+ );
+ expect(stickyHeaderEl.findComponent(GlIcon).props('name')).toBe(
+ issuableTitleProps.statusIcon,
+ );
expect(stickyHeaderEl.text()).toContain('Open');
expect(stickyHeaderEl.text()).toContain(issuableTitleProps.issuable.title);
});
diff --git a/spec/helpers/projects/pipeline_helper_spec.rb b/spec/helpers/projects/pipeline_helper_spec.rb
index 90cf3cb03f8..a52139710aa 100644
--- a/spec/helpers/projects/pipeline_helper_spec.rb
+++ b/spec/helpers/projects/pipeline_helper_spec.rb
@@ -14,10 +14,12 @@ RSpec.describe Projects::PipelineHelper do
it 'returns pipeline tabs data' do
expect(pipeline_tabs_data).to include({
can_generate_codequality_reports: pipeline.can_generate_codequality_reports?.to_json,
+ full_path: project.full_path,
graphql_resource_etag: graphql_etag_pipeline_path(pipeline),
metrics_path: namespace_project_ci_prometheus_metrics_histograms_path(namespace_id: project.namespace, project_id: project, format: :json),
pipeline_iid: pipeline.iid,
- pipeline_project_path: project.full_path
+ pipeline_project_path: project.full_path,
+ total_job_count: pipeline.total_size
})
end
end
diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb
index 8e2ec014383..4117d577f20 100644
--- a/spec/helpers/search_helper_spec.rb
+++ b/spec/helpers/search_helper_spec.rb
@@ -534,24 +534,26 @@ RSpec.describe SearchHelper do
end
describe '#repository_ref' do
+ using RSpec::Parameterized::TableSyntax
+
let_it_be(:project) { create(:project, :repository) }
- let(:params) { { repository_ref: 'the-repository-ref-param' } }
+ let(:default_branch) { project.default_branch }
+ let(:params) { { repository_ref: ref, project_id: project_id } }
subject { repository_ref(project) }
- it { is_expected.to eq('the-repository-ref-param') }
-
- context 'when the param :repository_ref is not set' do
- let(:params) { { repository_ref: nil } }
-
- it { is_expected.to eq(project.default_branch) }
+ where(:project_id, :ref, :expected_ref) do
+ 123 | 'ref-param' | 'ref-param'
+ 123 | nil | ref(:default_branch)
+ 123 | 111111 | '111111'
+ nil | 'ref-param' | ref(:default_branch)
end
- context 'when the repository_ref param is a number' do
- let(:params) { { repository_ref: 111111 } }
-
- it { is_expected.to eq('111111') }
+ with_them do
+ it 'returns expected_ref' do
+ expect(repository_ref(project)).to eq(expected_ref)
+ end
end
end
diff --git a/spec/lib/gitlab/ci/pipeline/chain/limit/rate_limit_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/limit/rate_limit_spec.rb
index aa8aec2af4a..6ac07d10aba 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/limit/rate_limit_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/limit/rate_limit_spec.rb
@@ -30,10 +30,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::RateLimit, :freeze_time, :c
context 'when the limit is exceeded' do
before do
- allow(Gitlab::ApplicationRateLimiter).to receive(:rate_limits)
- .and_return(pipelines_create: { threshold: 1, interval: 1.minute })
-
- stub_feature_flags(ci_throttle_pipelines_creation_dry_run: false)
+ stub_application_setting(pipeline_limit_per_project_user_sha: 1)
end
it 'does not persist the pipeline' do
@@ -101,33 +98,9 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::RateLimit, :freeze_time, :c
end
end
- context 'when ci_throttle_pipelines_creation is disabled' do
- before do
- stub_feature_flags(ci_throttle_pipelines_creation: false)
- end
-
- it 'does not break the chain' do
- perform
-
- expect(step.break?).to be_falsey
- end
-
- it 'does not invalidate the pipeline' do
- perform
-
- expect(pipeline.errors).to be_empty
- end
-
- it 'does not log anything' do
- expect(Gitlab::AppJsonLogger).not_to receive(:info)
-
- perform
- end
- end
-
- context 'when ci_throttle_pipelines_creation_dry_run is enabled' do
+ context 'when ci_enforce_throttle_pipelines_creation is disabled' do
before do
- stub_feature_flags(ci_throttle_pipelines_creation_dry_run: true)
+ stub_feature_flags(ci_enforce_throttle_pipelines_creation: false)
end
it 'does not break the chain' do
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index c00509a9b64..74bbe1c50ca 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -1367,7 +1367,7 @@ RSpec.describe Ci::Build do
before do
allow(Deployments::LinkMergeRequestWorker).to receive(:perform_async)
- allow(Deployments::HooksWorker).to receive(:perform_async)
+ allow(deployment).to receive(:execute_hooks)
end
it 'has deployments record with created status' do
@@ -1423,7 +1423,7 @@ RSpec.describe Ci::Build do
before do
allow(Deployments::UpdateEnvironmentWorker).to receive(:perform_async)
- allow(Deployments::HooksWorker).to receive(:perform_async)
+ allow(deployment).to receive(:execute_hooks)
end
it_behaves_like 'avoid deadlock'
@@ -1509,14 +1509,28 @@ RSpec.describe Ci::Build do
it 'transitions to running and calls webhook' do
freeze_time do
- expect(Deployments::HooksWorker)
- .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current)
+ expect(deployment).to receive(:execute_hooks).with(Time.current)
subject
end
expect(deployment).to be_running
end
+
+ context 'when `deployment_hooks_skip_worker` flag is disabled' do
+ before do
+ stub_feature_flags(deployment_hooks_skip_worker: false)
+ end
+
+ it 'executes Deployments::HooksWorker asynchronously' do
+ freeze_time do
+ expect(Deployments::HooksWorker)
+ .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current)
+
+ subject
+ end
+ end
+ end
end
end
end
diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb
index 409353bdbcf..8096604b965 100644
--- a/spec/models/deployment_spec.rb
+++ b/spec/models/deployment_spec.rb
@@ -137,15 +137,29 @@ RSpec.describe Deployment do
end
end
- it 'executes Deployments::HooksWorker asynchronously' do
+ it 'executes deployment hooks' do
freeze_time do
- expect(Deployments::HooksWorker)
- .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current)
+ expect(deployment).to receive(:execute_hooks).with(Time.current)
deployment.run!
end
end
+ context 'when `deployment_hooks_skip_worker` flag is disabled' do
+ before do
+ stub_feature_flags(deployment_hooks_skip_worker: false)
+ end
+
+ it 'executes Deployments::HooksWorker asynchronously' do
+ freeze_time do
+ expect(Deployments::HooksWorker)
+ .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current)
+
+ deployment.run!
+ end
+ end
+ end
+
it 'executes Deployments::DropOlderDeploymentsWorker asynchronously' do
expect(Deployments::DropOlderDeploymentsWorker)
.to receive(:perform_async).once.with(deployment.id)
@@ -173,14 +187,28 @@ RSpec.describe Deployment do
deployment.succeed!
end
- it 'executes Deployments::HooksWorker asynchronously' do
+ it 'executes deployment hooks' do
freeze_time do
- expect(Deployments::HooksWorker)
- .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current)
+ expect(deployment).to receive(:execute_hooks).with(Time.current)
deployment.succeed!
end
end
+
+ context 'when `deployment_hooks_skip_worker` flag is disabled' do
+ before do
+ stub_feature_flags(deployment_hooks_skip_worker: false)
+ end
+
+ it 'executes Deployments::HooksWorker asynchronously' do
+ freeze_time do
+ expect(Deployments::HooksWorker)
+ .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current)
+
+ deployment.succeed!
+ end
+ end
+ end
end
context 'when deployment failed' do
@@ -202,14 +230,28 @@ RSpec.describe Deployment do
deployment.drop!
end
- it 'executes Deployments::HooksWorker asynchronously' do
+ it 'executes deployment hooks' do
freeze_time do
- expect(Deployments::HooksWorker)
- .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current)
+ expect(deployment).to receive(:execute_hooks).with(Time.current)
deployment.drop!
end
end
+
+ context 'when `deployment_hooks_skip_worker` flag is disabled' do
+ before do
+ stub_feature_flags(deployment_hooks_skip_worker: false)
+ end
+
+ it 'executes Deployments::HooksWorker asynchronously' do
+ freeze_time do
+ expect(Deployments::HooksWorker)
+ .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current)
+
+ deployment.drop!
+ end
+ end
+ end
end
context 'when deployment was canceled' do
@@ -231,14 +273,28 @@ RSpec.describe Deployment do
deployment.cancel!
end
- it 'executes Deployments::HooksWorker asynchronously' do
+ it 'executes deployment hooks' do
freeze_time do
- expect(Deployments::HooksWorker)
- .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current)
+ expect(deployment).to receive(:execute_hooks).with(Time.current)
deployment.cancel!
end
end
+
+ context 'when `deployment_hooks_skip_worker` flag is disabled' do
+ before do
+ stub_feature_flags(deployment_hooks_skip_worker: false)
+ end
+
+ it 'executes Deployments::HooksWorker asynchronously' do
+ freeze_time do
+ expect(Deployments::HooksWorker)
+ .to receive(:perform_async).with(deployment_id: deployment.id, status_changed_at: Time.current)
+
+ deployment.cancel!
+ end
+ end
+ end
end
context 'when deployment was skipped' do
@@ -266,6 +322,12 @@ RSpec.describe Deployment do
deployment.skip!
end
end
+
+ it 'does not execute deployment hooks' do
+ expect(deployment).not_to receive(:execute_hooks)
+
+ deployment.skip!
+ end
end
context 'when deployment is blocked' do
@@ -289,6 +351,12 @@ RSpec.describe Deployment do
deployment.block!
end
+
+ it 'does not execute deployment hooks' do
+ expect(deployment).not_to receive(:execute_hooks)
+
+ deployment.block!
+ end
end
describe 'synching status to Jira' do
@@ -845,11 +913,30 @@ RSpec.describe Deployment do
expect(Deployments::UpdateEnvironmentWorker).to receive(:perform_async)
expect(Deployments::LinkMergeRequestWorker).to receive(:perform_async)
expect(Deployments::ArchiveInProjectWorker).to receive(:perform_async)
- expect(Deployments::HooksWorker).to receive(:perform_async)
expect(deploy.update_status('success')).to eq(true)
end
+ context 'when `deployment_hooks_skip_worker` flag is disabled' do
+ before do
+ stub_feature_flags(deployment_hooks_skip_worker: false)
+ end
+
+ it 'schedules `Deployments::HooksWorker` when finishing a deploy' do
+ expect(Deployments::HooksWorker).to receive(:perform_async)
+
+ deploy.update_status('success')
+ end
+ end
+
+ it 'executes deployment hooks when finishing a deploy' do
+ freeze_time do
+ expect(deploy).to receive(:execute_hooks).with(Time.current)
+
+ deploy.update_status('success')
+ end
+ end
+
it 'updates finished_at when transitioning to a finished status' do
freeze_time do
deploy.update_status('success')
diff --git a/spec/services/ci/create_pipeline_service/rate_limit_spec.rb b/spec/services/ci/create_pipeline_service/rate_limit_spec.rb
index caea165cc6c..fbd8b41de63 100644
--- a/spec/services/ci/create_pipeline_service/rate_limit_spec.rb
+++ b/spec/services/ci/create_pipeline_service/rate_limit_spec.rb
@@ -10,10 +10,7 @@ RSpec.describe Ci::CreatePipelineService, :freeze_time, :clean_gitlab_redis_rate
before do
stub_ci_pipeline_yaml_file(gitlab_ci_yaml)
- stub_feature_flags(ci_throttle_pipelines_creation_dry_run: false)
-
- allow(Gitlab::ApplicationRateLimiter).to receive(:rate_limits)
- .and_return(pipelines_create: { threshold: 1, interval: 1.minute })
+ stub_application_setting(pipeline_limit_per_project_user_sha: 1)
end
context 'when user is under the limit' do
diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb
index c39a76ad2fc..6f59caaa7e5 100644
--- a/spec/services/ci/create_pipeline_service_spec.rb
+++ b/spec/services/ci/create_pipeline_service_spec.rb
@@ -12,10 +12,6 @@ RSpec.describe Ci::CreatePipelineService do
before do
stub_ci_pipeline_to_return_yaml_file
-
- # Disable rate limiting for pipeline creation
- allow(Gitlab::ApplicationRateLimiter).to receive(:rate_limits)
- .and_return(pipelines_create: { threshold: 0, interval: 1.minute })
end
describe '#execute' do
diff --git a/spec/services/deployments/create_service_spec.rb b/spec/services/deployments/create_service_spec.rb
index 0f2a6ce32e1..f6f4c68a6f1 100644
--- a/spec/services/deployments/create_service_spec.rb
+++ b/spec/services/deployments/create_service_spec.rb
@@ -21,11 +21,34 @@ RSpec.describe Deployments::CreateService do
expect(Deployments::UpdateEnvironmentWorker).to receive(:perform_async)
expect(Deployments::LinkMergeRequestWorker).to receive(:perform_async)
- expect(Deployments::HooksWorker).to receive(:perform_async)
+ expect_next_instance_of(Deployment) do |deployment|
+ expect(deployment).to receive(:execute_hooks)
+ end
expect(service.execute).to be_persisted
end
+ context 'when `deployment_hooks_skip_worker` flag is disabled' do
+ before do
+ stub_feature_flags(deployment_hooks_skip_worker: false)
+ end
+
+ it 'executes Deployments::HooksWorker asynchronously' do
+ service = described_class.new(
+ environment,
+ user,
+ sha: 'b83d6e391c22777fca1ed3012fce84f633d7fed0',
+ ref: 'master',
+ tag: false,
+ status: 'success'
+ )
+
+ expect(Deployments::HooksWorker).to receive(:perform_async)
+
+ service.execute
+ end
+ end
+
it 'does not change the status if no status is given' do
service = described_class.new(
environment,
@@ -37,7 +60,9 @@ RSpec.describe Deployments::CreateService do
expect(Deployments::UpdateEnvironmentWorker).not_to receive(:perform_async)
expect(Deployments::LinkMergeRequestWorker).not_to receive(:perform_async)
- expect(Deployments::HooksWorker).not_to receive(:perform_async)
+ expect_next_instance_of(Deployment) do |deployment|
+ expect(deployment).not_to receive(:execute_hooks)
+ end
expect(service.execute).to be_persisted
end
@@ -55,11 +80,9 @@ RSpec.describe Deployments::CreateService do
it 'does not create a new deployment' do
described_class.new(environment, user, params).execute
- expect(Deployments::UpdateEnvironmentWorker).not_to receive(:perform_async)
- expect(Deployments::LinkMergeRequestWorker).not_to receive(:perform_async)
- expect(Deployments::HooksWorker).not_to receive(:perform_async)
-
- described_class.new(environment.reload, user, params).execute
+ expect do
+ described_class.new(environment.reload, user, params).execute
+ end.not_to change { Deployment.count }
end
end
end
diff --git a/spec/services/deployments/update_environment_service_spec.rb b/spec/services/deployments/update_environment_service_spec.rb
index 0859aa2c9d1..fe246ce9d23 100644
--- a/spec/services/deployments/update_environment_service_spec.rb
+++ b/spec/services/deployments/update_environment_service_spec.rb
@@ -33,7 +33,7 @@ RSpec.describe Deployments::UpdateEnvironmentService do
before do
allow(Deployments::LinkMergeRequestWorker).to receive(:perform_async)
- allow(Deployments::HooksWorker).to receive(:perform_async)
+ allow(deployment).to receive(:execute_hooks)
job.success! # Create/Succeed deployment
end