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-24 21:09:18 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-24 21:09:18 +0300
commit8015f09545c35b833f4955fc2e0b8f1a3214cbcb (patch)
treee28c5add700b9f3d12eabe1361889545785b29d4 /spec
parent8e1bb8745bafe36f273ce4a095c3576c38ceb8b4 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/merge_requests.rb4
-rw-r--r--spec/factories/sequences.rb1
-rw-r--r--spec/fixtures/security_reports/feature-branch/gl-secret-detection-report.json2
-rw-r--r--spec/fixtures/security_reports/master/gl-sast-missing-scanner.json2
-rw-r--r--spec/fixtures/security_reports/master/gl-secret-detection-report.json2
-rw-r--r--spec/frontend/content_editor/components/__snapshots__/toolbar_link_button_spec.js.snap16
-rw-r--r--spec/frontend/error_tracking_settings/components/app_spec.js2
-rw-r--r--spec/frontend/profile/account/components/update_username_spec.js2
-rw-r--r--spec/frontend/projects/new/components/new_project_push_tip_popover_spec.js2
-rw-r--r--spec/frontend/vue_shared/components/__snapshots__/clone_dropdown_spec.js.snap118
-rw-r--r--spec/lib/gitlab/ci/parsers/security/secret_detection_spec.rb2
-rw-r--r--spec/lib/gitlab/database/load_balancing/configuration_spec.rb61
-rw-r--r--spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb40
-rw-r--r--spec/lib/gitlab/database/load_balancing/setup_spec.rb149
-rw-r--r--spec/lib/gitlab/database/query_analyzers/gitlab_schemas_metrics_spec.rb73
-rw-r--r--spec/lib/gitlab/database_spec.rb19
-rw-r--r--spec/lib/gitlab/mail_room/mail_room_spec.rb2
-rw-r--r--spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb4
-rw-r--r--spec/lib/marginalia_spec.rb2
-rw-r--r--spec/migrations/20220523171107_drop_deploy_tokens_token_column_spec.rb22
-rw-r--r--spec/models/merge_request_spec.rb105
-rw-r--r--spec/requests/api/internal/mail_room_spec.rb24
-rw-r--r--spec/spec_helper.rb10
23 files changed, 230 insertions, 434 deletions
diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb
index e897a5e022a..cba66b5d414 100644
--- a/spec/factories/merge_requests.rb
+++ b/spec/factories/merge_requests.rb
@@ -25,10 +25,6 @@ FactoryBot.define do
title { generate(:draft_title) }
end
- trait :wip_merge_request do
- title { generate(:wip_title) }
- end
-
trait :jira_title do
title { generate(:jira_title) }
end
diff --git a/spec/factories/sequences.rb b/spec/factories/sequences.rb
index 6b86154aa91..c10fab8588d 100644
--- a/spec/factories/sequences.rb
+++ b/spec/factories/sequences.rb
@@ -16,7 +16,6 @@ FactoryBot.define do
sequence(:oid) { |n| Digest::SHA2.hexdigest("oid-like-#{n}") }
sequence(:variable) { |n| "var#{n}" }
sequence(:draft_title) { |n| "Draft: #{n}" }
- sequence(:wip_title) { |n| "WIP: #{n}" }
sequence(:jira_title) { |n| "[PROJ-#{n}]: fix bug" }
sequence(:jira_description) { |n| "This is a description\n here is the description\n Related to: PROJ-#{n}" }
sequence(:jira_branch) { |n| "feature/PROJ-#{n}" }
diff --git a/spec/fixtures/security_reports/feature-branch/gl-secret-detection-report.json b/spec/fixtures/security_reports/feature-branch/gl-secret-detection-report.json
index 57a4dee3ddd..538364f84a2 100644
--- a/spec/fixtures/security_reports/feature-branch/gl-secret-detection-report.json
+++ b/spec/fixtures/security_reports/feature-branch/gl-secret-detection-report.json
@@ -1,5 +1,5 @@
{
- "version": "3.0",
+ "version": "14.1.2",
"vulnerabilities": [],
"remediations": []
}
diff --git a/spec/fixtures/security_reports/master/gl-sast-missing-scanner.json b/spec/fixtures/security_reports/master/gl-sast-missing-scanner.json
index f65580145b4..ab3ee348263 100644
--- a/spec/fixtures/security_reports/master/gl-sast-missing-scanner.json
+++ b/spec/fixtures/security_reports/master/gl-sast-missing-scanner.json
@@ -1,5 +1,5 @@
{
- "version": "1.2",
+ "version": "14.1.2",
"vulnerabilities": [
{
"category": "sast",
diff --git a/spec/fixtures/security_reports/master/gl-secret-detection-report.json b/spec/fixtures/security_reports/master/gl-secret-detection-report.json
index f0250ec9145..9b0b2a19beb 100644
--- a/spec/fixtures/security_reports/master/gl-secret-detection-report.json
+++ b/spec/fixtures/security_reports/master/gl-secret-detection-report.json
@@ -1,5 +1,5 @@
{
- "version": "3.0",
+ "version": "14.1.2",
"vulnerabilities": [
{
"id": "27d2322d519c94f803ffed1cf6d14e455df97e5a0668e229eb853fdb0d277d2c",
diff --git a/spec/frontend/content_editor/components/__snapshots__/toolbar_link_button_spec.js.snap b/spec/frontend/content_editor/components/__snapshots__/toolbar_link_button_spec.js.snap
index 7abd6b422ad..b54f7cf17c8 100644
--- a/spec/frontend/content_editor/components/__snapshots__/toolbar_link_button_spec.js.snap
+++ b/spec/frontend/content_editor/components/__snapshots__/toolbar_link_button_spec.js.snap
@@ -16,15 +16,13 @@ exports[`content_editor/components/toolbar_link_button renders dropdown componen
<!---->
<li role=\\"presentation\\" class=\\"gl-px-3!\\">
<form tabindex=\\"-1\\" class=\\"b-dropdown-form gl-p-0\\">
- <div placeholder=\\"Link URL\\">
- <div role=\\"group\\" class=\\"input-group\\">
- <!---->
- <!----> <input type=\\"text\\" placeholder=\\"Link URL\\" class=\\"form-control gl-form-input\\">
- <div class=\\"input-group-append\\"><button type=\\"button\\" class=\\"btn btn-confirm btn-md gl-button\\">
- <!---->
- <!----> <span class=\\"gl-button-text\\">Apply</span></button></div>
- <!---->
- </div>
+ <div role=\\"group\\" class=\\"input-group\\" placeholder=\\"Link URL\\">
+ <!---->
+ <!----> <input type=\\"text\\" placeholder=\\"Link URL\\" class=\\"form-control gl-form-input\\">
+ <div class=\\"input-group-append\\"><button type=\\"button\\" class=\\"btn btn-confirm btn-md gl-button\\">
+ <!---->
+ <!----> <span class=\\"gl-button-text\\">Apply</span></button></div>
+ <!---->
</div>
</form>
</li>
diff --git a/spec/frontend/error_tracking_settings/components/app_spec.js b/spec/frontend/error_tracking_settings/components/app_spec.js
index 4a0bbb1acbe..c660c9c4a99 100644
--- a/spec/frontend/error_tracking_settings/components/app_spec.js
+++ b/spec/frontend/error_tracking_settings/components/app_spec.js
@@ -177,7 +177,7 @@ describe('error tracking settings app', () => {
const clipBoardButton = findDsnSettings().findComponent(ClipboardButton);
expect(clipBoardInput.props('value')).toBe(TEST_GITLAB_DSN);
- expect(clipBoardInput.attributes('readonly')).toBeTruthy();
+ expect(clipBoardInput.attributes('readonly')).toBe('');
expect(clipBoardButton.props('text')).toBe(TEST_GITLAB_DSN);
});
});
diff --git a/spec/frontend/profile/account/components/update_username_spec.js b/spec/frontend/profile/account/components/update_username_spec.js
index e342b7c4ba1..0e56bccf27e 100644
--- a/spec/frontend/profile/account/components/update_username_spec.js
+++ b/spec/frontend/profile/account/components/update_username_spec.js
@@ -52,7 +52,7 @@ describe('UpdateUsername component', () => {
openModalBtn: wrapper.find('[data-testid="username-change-confirmation-modal"]'),
modalBody: modal.find('.modal-body'),
modalHeader: modal.find('.modal-title'),
- confirmModalBtn: wrapper.find('.btn-warning'),
+ confirmModalBtn: wrapper.find('.btn-confirm'),
};
};
diff --git a/spec/frontend/projects/new/components/new_project_push_tip_popover_spec.js b/spec/frontend/projects/new/components/new_project_push_tip_popover_spec.js
index 42259a5c392..f50dd393174 100644
--- a/spec/frontend/projects/new/components/new_project_push_tip_popover_spec.js
+++ b/spec/frontend/projects/new/components/new_project_push_tip_popover_spec.js
@@ -57,7 +57,7 @@ describe('New project push tip popover', () => {
});
expect(findFormInput().attributes()).toMatchObject({
'aria-label': 'Push project from command line',
- readonly: 'readonly',
+ readonly: '',
});
});
diff --git a/spec/frontend/vue_shared/components/__snapshots__/clone_dropdown_spec.js.snap b/spec/frontend/vue_shared/components/__snapshots__/clone_dropdown_spec.js.snap
index 44b4c0398cd..cf2ed3331b7 100644
--- a/spec/frontend/vue_shared/components/__snapshots__/clone_dropdown_spec.js.snap
+++ b/spec/frontend/vue_shared/components/__snapshots__/clone_dropdown_spec.js.snap
@@ -24,41 +24,38 @@ exports[`Clone Dropdown Button rendering matches the snapshot 1`] = `
<div
class="mx-3"
>
- <div
- readonly="readonly"
+ <b-input-group-stub
+ readonly=""
+ tag="div"
>
- <b-input-group-stub
+ <!---->
+
+ <b-form-input-stub
+ class="gl-form-input"
+ debounce="0"
+ formatter="[Function]"
+ readonly="true"
+ type="text"
+ value="ssh://foo.bar"
+ />
+
+ <b-input-group-append-stub
tag="div"
>
- <!---->
-
- <b-form-input-stub
- class="gl-form-input"
- debounce="0"
- formatter="[Function]"
- readonly="true"
- type="text"
- value="ssh://foo.bar"
+ <gl-button-stub
+ aria-label="Copy URL"
+ buttontextclasses=""
+ category="primary"
+ class="d-inline-flex"
+ data-clipboard-text="ssh://foo.bar"
+ data-qa-selector="copy_ssh_url_button"
+ icon="copy-to-clipboard"
+ size="medium"
+ title="Copy URL"
+ variant="default"
/>
-
- <b-input-group-append-stub
- tag="div"
- >
- <gl-button-stub
- aria-label="Copy URL"
- buttontextclasses=""
- category="primary"
- class="d-inline-flex"
- data-clipboard-text="ssh://foo.bar"
- data-qa-selector="copy_ssh_url_button"
- icon="copy-to-clipboard"
- size="medium"
- title="Copy URL"
- variant="default"
- />
- </b-input-group-append-stub>
- </b-input-group-stub>
- </div>
+ </b-input-group-append-stub>
+ </b-input-group-stub>
</div>
<gl-dropdown-section-header-stub>
@@ -68,41 +65,38 @@ exports[`Clone Dropdown Button rendering matches the snapshot 1`] = `
<div
class="mx-3"
>
- <div
- readonly="readonly"
+ <b-input-group-stub
+ readonly=""
+ tag="div"
>
- <b-input-group-stub
+ <!---->
+
+ <b-form-input-stub
+ class="gl-form-input"
+ debounce="0"
+ formatter="[Function]"
+ readonly="true"
+ type="text"
+ value="http://foo.bar"
+ />
+
+ <b-input-group-append-stub
tag="div"
>
- <!---->
-
- <b-form-input-stub
- class="gl-form-input"
- debounce="0"
- formatter="[Function]"
- readonly="true"
- type="text"
- value="http://foo.bar"
+ <gl-button-stub
+ aria-label="Copy URL"
+ buttontextclasses=""
+ category="primary"
+ class="d-inline-flex"
+ data-clipboard-text="http://foo.bar"
+ data-qa-selector="copy_http_url_button"
+ icon="copy-to-clipboard"
+ size="medium"
+ title="Copy URL"
+ variant="default"
/>
-
- <b-input-group-append-stub
- tag="div"
- >
- <gl-button-stub
- aria-label="Copy URL"
- buttontextclasses=""
- category="primary"
- class="d-inline-flex"
- data-clipboard-text="http://foo.bar"
- data-qa-selector="copy_http_url_button"
- icon="copy-to-clipboard"
- size="medium"
- title="Copy URL"
- variant="default"
- />
- </b-input-group-append-stub>
- </b-input-group-stub>
- </div>
+ </b-input-group-append-stub>
+ </b-input-group-stub>
</div>
</div>
</gl-dropdown-stub>
diff --git a/spec/lib/gitlab/ci/parsers/security/secret_detection_spec.rb b/spec/lib/gitlab/ci/parsers/security/secret_detection_spec.rb
index 1d361e16aad..e8f1d617cb7 100644
--- a/spec/lib/gitlab/ci/parsers/security/secret_detection_spec.rb
+++ b/spec/lib/gitlab/ci/parsers/security/secret_detection_spec.rb
@@ -39,7 +39,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::SecretDetection do
end
it "generates expected metadata_version" do
- expect(report.findings.first.metadata_version).to eq('3.0')
+ expect(report.findings.first.metadata_version).to eq('14.1.2')
end
end
end
diff --git a/spec/lib/gitlab/database/load_balancing/configuration_spec.rb b/spec/lib/gitlab/database/load_balancing/configuration_spec.rb
index 77284b4d128..34370c9a21f 100644
--- a/spec/lib/gitlab/database/load_balancing/configuration_spec.rb
+++ b/spec/lib/gitlab/database/load_balancing/configuration_spec.rb
@@ -100,14 +100,6 @@ RSpec.describe Gitlab::Database::LoadBalancing::Configuration, :request_store do
expect(config.pool_size).to eq(4)
end
end
-
- it 'calls reuse_primary_connection!' do
- expect_next_instance_of(described_class) do |subject|
- expect(subject).to receive(:reuse_primary_connection!).and_call_original
- end
-
- described_class.for_model(model)
- end
end
describe '#load_balancing_enabled?' do
@@ -203,61 +195,12 @@ RSpec.describe Gitlab::Database::LoadBalancing::Configuration, :request_store do
end
end
- describe '#replica_db_config' do
+ describe '#db_config' do
let(:model) { double(:model, connection_db_config: db_config, connection_specification_name: 'Ci::ApplicationRecord') }
let(:config) { described_class.for_model(model) }
it 'returns exactly db_config' do
- expect(config.replica_db_config).to eq(db_config)
- end
-
- context 'when GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci=main' do
- it 'does not change replica_db_config' do
- stub_env('GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci', 'main')
-
- expect(config.replica_db_config).to eq(db_config)
- end
- end
- end
-
- describe 'reuse_primary_connection!' do
- let(:model) { double(:model, connection_db_config: db_config, connection_specification_name: 'Ci::ApplicationRecord') }
- let(:config) { described_class.for_model(model) }
-
- context 'when GITLAB_LOAD_BALANCING_REUSE_PRIMARY_* not configured' do
- it 'the primary connection uses default specification' do
- stub_env('GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci', nil)
-
- expect(config.primary_connection_specification_name).to eq('Ci::ApplicationRecord')
- end
- end
-
- context 'when GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci=main' do
- before do
- stub_env('GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci', 'main')
- end
-
- it 'the primary connection uses main connection' do
- expect(config.primary_connection_specification_name).to eq('ActiveRecord::Base')
- end
-
- context 'when force_no_sharing_primary_model feature flag is enabled' do
- before do
- stub_feature_flags(force_no_sharing_primary_model: true)
- end
-
- it 'the primary connection uses ci connection' do
- expect(config.primary_connection_specification_name).to eq('Ci::ApplicationRecord')
- end
- end
- end
-
- context 'when GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci=unknown' do
- it 'raises exception' do
- stub_env('GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci', 'unknown')
-
- expect { config.reuse_primary_connection! }.to raise_error /Invalid value for/
- end
+ expect(config.db_config).to eq(db_config)
end
end
end
diff --git a/spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb b/spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb
index 3c7819c04b6..34eb64997c1 100644
--- a/spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb
+++ b/spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb
@@ -487,46 +487,6 @@ RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do
end
end
- describe 'primary connection re-use', :reestablished_active_record_base, :add_ci_connection do
- let(:model) { Ci::ApplicationRecord }
-
- describe '#read' do
- it 'returns ci replica connection' do
- expect { |b| lb.read(&b) }.to yield_with_args do |args|
- expect(args.pool.db_config.name).to eq('ci_replica')
- end
- end
-
- context 'when GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci=main' do
- it 'returns ci replica connection' do
- stub_env('GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci', 'main')
-
- expect { |b| lb.read(&b) }.to yield_with_args do |args|
- expect(args.pool.db_config.name).to eq('ci_replica')
- end
- end
- end
- end
-
- describe '#read_write' do
- it 'returns Ci::ApplicationRecord connection' do
- expect { |b| lb.read_write(&b) }.to yield_with_args do |args|
- expect(args.pool.db_config.name).to eq('ci')
- end
- end
-
- context 'when GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci=main' do
- it 'returns ActiveRecord::Base connection' do
- stub_env('GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci', 'main')
-
- expect { |b| lb.read_write(&b) }.to yield_with_args do |args|
- expect(args.pool.db_config.name).to eq('main')
- end
- end
- end
- end
- end
-
describe '#wal_diff' do
it 'returns the diff between two write locations' do
loc1 = lb.send(:get_write_location, lb.pool.connection)
diff --git a/spec/lib/gitlab/database/load_balancing/setup_spec.rb b/spec/lib/gitlab/database/load_balancing/setup_spec.rb
index c44637b8d06..fa6d71bca7f 100644
--- a/spec/lib/gitlab/database/load_balancing/setup_spec.rb
+++ b/spec/lib/gitlab/database/load_balancing/setup_spec.rb
@@ -122,123 +122,68 @@ RSpec.describe Gitlab::Database::LoadBalancing::Setup do
context 'uses correct base models', :reestablished_active_record_base do
using RSpec::Parameterized::TableSyntax
- where do
- {
- "it picks a dedicated CI connection" => {
- env_GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci: nil,
- request_store_active: false,
- ff_force_no_sharing_primary_model: false,
- expectations: {
- main: { read: 'main_replica', write: 'main' },
- ci: { read: 'ci_replica', write: 'ci' }
- }
- },
- "with re-use of primary connection it uses CI connection for reads" => {
- env_GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci: 'main',
- request_store_active: false,
- ff_force_no_sharing_primary_model: false,
- expectations: {
- main: { read: 'main_replica', write: 'main' },
- ci: { read: 'ci_replica', write: 'main' }
- }
- },
- "with re-use and FF force_no_sharing_primary_model enabled with RequestStore it sticks FF and uses CI connection for reads and writes" => {
- env_GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci: 'main',
- request_store_active: true,
- ff_force_no_sharing_primary_model: true,
- expectations: {
- main: { read: 'main_replica', write: 'main' },
- ci: { read: 'ci_replica', write: 'ci' }
- }
- },
- "with re-use and FF force_no_sharing_primary_model enabled without RequestStore it doesn't use FF and uses CI connection for reads only" => {
- env_GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci: 'main',
- request_store_active: true,
- ff_force_no_sharing_primary_model: false,
- expectations: {
- main: { read: 'main_replica', write: 'main' },
- ci: { read: 'ci_replica', write: 'main' }
- }
- }
- }
- end
-
- with_them do
- let(:ci_class) do
- Class.new(ActiveRecord::Base) do
- def self.name
- 'Ci::ApplicationRecordTemporary'
- end
-
- establish_connection ActiveRecord::DatabaseConfigurations::HashConfig.new(
- Rails.env,
- 'ci',
- ActiveRecord::Base.connection_db_config.configuration_hash
- )
+ let(:ci_class) do
+ Class.new(ActiveRecord::Base) do
+ def self.name
+ 'Ci::ApplicationRecordTemporary'
end
- end
- let(:models) do
- {
- main: ActiveRecord::Base,
- ci: ci_class
- }
+ establish_connection ActiveRecord::DatabaseConfigurations::HashConfig.new(
+ Rails.env,
+ 'ci',
+ ActiveRecord::Base.connection_db_config.configuration_hash
+ )
end
+ end
- around do |example|
- if request_store_active
- Gitlab::WithRequestStore.with_request_store do
- stub_feature_flags(force_no_sharing_primary_model: ff_force_no_sharing_primary_model)
- RequestStore.clear!
-
- example.run
- end
- else
- example.run
- end
- end
+ let(:models) do
+ {
+ main: ActiveRecord::Base,
+ ci: ci_class
+ }
+ end
- before do
- allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)
+ before do
+ allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)
- # Rewrite `class_attribute` to use rspec mocking and prevent modifying the objects
- allow_next_instance_of(described_class) do |setup|
- allow(setup).to receive(:configure_connection)
+ # Rewrite `class_attribute` to use rspec mocking and prevent modifying the objects
+ allow_next_instance_of(described_class) do |setup|
+ allow(setup).to receive(:configure_connection)
- allow(setup).to receive(:setup_class_attribute) do |attribute, value|
- allow(setup.model).to receive(attribute) { value }
- end
+ allow(setup).to receive(:setup_class_attribute) do |attribute, value|
+ allow(setup.model).to receive(attribute) { value }
end
+ end
- stub_env('GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci', env_GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci)
-
- # Make load balancer to force init with a dedicated replicas connections
- models.each do |_, model|
- described_class.new(model).tap do |subject|
- subject.configuration.hosts = [subject.configuration.replica_db_config.host]
- subject.setup
- end
+ # Make load balancer to force init with a dedicated replicas connections
+ models.each do |_, model|
+ described_class.new(model).tap do |subject|
+ subject.configuration.hosts = [subject.configuration.db_config.host]
+ subject.setup
end
end
+ end
- it 'results match expectations' do
- result = models.transform_values do |model|
- load_balancer = model.connection.instance_variable_get(:@load_balancer)
-
- {
- read: load_balancer.read { |connection| connection.pool.db_config.name },
- write: load_balancer.read_write { |connection| connection.pool.db_config.name }
- }
- end
+ it 'results match expectations' do
+ result = models.transform_values do |model|
+ load_balancer = model.connection.instance_variable_get(:@load_balancer)
- expect(result).to eq(expectations)
+ {
+ read: load_balancer.read { |connection| connection.pool.db_config.name },
+ write: load_balancer.read_write { |connection| connection.pool.db_config.name }
+ }
end
- it 'does return load_balancer assigned to a given connection' do
- models.each do |name, model|
- expect(model.load_balancer.name).to eq(name)
- expect(model.sticking.instance_variable_get(:@load_balancer)).to eq(model.load_balancer)
- end
+ expect(result).to eq({
+ main: { read: 'main_replica', write: 'main' },
+ ci: { read: 'ci_replica', write: 'ci' }
+ })
+ end
+
+ it 'does return load_balancer assigned to a given connection' do
+ models.each do |name, model|
+ expect(model.load_balancer.name).to eq(name)
+ expect(model.sticking.instance_variable_get(:@load_balancer)).to eq(model.load_balancer)
end
end
end
diff --git a/spec/lib/gitlab/database/query_analyzers/gitlab_schemas_metrics_spec.rb b/spec/lib/gitlab/database/query_analyzers/gitlab_schemas_metrics_spec.rb
index 0d687db0f96..62c5ead855a 100644
--- a/spec/lib/gitlab/database/query_analyzers/gitlab_schemas_metrics_spec.rb
+++ b/spec/lib/gitlab/database/query_analyzers/gitlab_schemas_metrics_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasMetrics, query_ana
process_sql(ActiveRecord::Base, "SELECT 1 FROM projects")
end
- context 'properly observes all queries', :add_ci_connection, :request_store do
+ context 'properly observes all queries', :add_ci_connection do
using RSpec::Parameterized::TableSyntax
where do
@@ -28,8 +28,7 @@ RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasMetrics, query_ana
expectations: {
gitlab_schemas: "gitlab_main",
db_config_name: "main"
- },
- setup: nil
+ }
},
"for query accessing gitlab_ci and gitlab_main" => {
model: ApplicationRecord,
@@ -37,8 +36,7 @@ RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasMetrics, query_ana
expectations: {
gitlab_schemas: "gitlab_ci,gitlab_main",
db_config_name: "main"
- },
- setup: nil
+ }
},
"for query accessing gitlab_ci and gitlab_main the gitlab_schemas is always ordered" => {
model: ApplicationRecord,
@@ -46,8 +44,7 @@ RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasMetrics, query_ana
expectations: {
gitlab_schemas: "gitlab_ci,gitlab_main",
db_config_name: "main"
- },
- setup: nil
+ }
},
"for query accessing CI database" => {
model: Ci::ApplicationRecord,
@@ -56,62 +53,6 @@ RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasMetrics, query_ana
gitlab_schemas: "gitlab_ci",
db_config_name: "ci"
}
- },
- "for query accessing CI database with re-use and disabled sharing" => {
- model: Ci::ApplicationRecord,
- sql: "SELECT 1 FROM ci_builds",
- expectations: {
- gitlab_schemas: "gitlab_ci",
- db_config_name: "ci",
- ci_dedicated_primary_connection: true
- },
- setup: ->(_) do
- skip_if_multiple_databases_not_setup
- stub_env('GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci', 'main')
- stub_feature_flags(force_no_sharing_primary_model: true)
- end
- },
- "for query accessing CI database with re-use and enabled sharing" => {
- model: Ci::ApplicationRecord,
- sql: "SELECT 1 FROM ci_builds",
- expectations: {
- gitlab_schemas: "gitlab_ci",
- db_config_name: "ci",
- ci_dedicated_primary_connection: false
- },
- setup: ->(_) do
- skip_if_multiple_databases_not_setup
- stub_env('GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci', 'main')
- stub_feature_flags(force_no_sharing_primary_model: false)
- end
- },
- "for query accessing CI database without re-use and disabled sharing" => {
- model: Ci::ApplicationRecord,
- sql: "SELECT 1 FROM ci_builds",
- expectations: {
- gitlab_schemas: "gitlab_ci",
- db_config_name: "ci",
- ci_dedicated_primary_connection: true
- },
- setup: ->(_) do
- skip_if_multiple_databases_not_setup
- stub_env('GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci', nil)
- stub_feature_flags(force_no_sharing_primary_model: true)
- end
- },
- "for query accessing CI database without re-use and enabled sharing" => {
- model: Ci::ApplicationRecord,
- sql: "SELECT 1 FROM ci_builds",
- expectations: {
- gitlab_schemas: "gitlab_ci",
- db_config_name: "ci",
- ci_dedicated_primary_connection: true
- },
- setup: ->(_) do
- skip_if_multiple_databases_not_setup
- stub_env('GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci', nil)
- stub_feature_flags(force_no_sharing_primary_model: false)
- end
}
}
end
@@ -122,15 +63,11 @@ RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasMetrics, query_ana
end
it do
- stub_env('GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci', nil)
-
- instance_eval(&setup) if setup
-
allow(::Ci::ApplicationRecord.load_balancer).to receive(:configuration)
.and_return(Gitlab::Database::LoadBalancing::Configuration.for_model(::Ci::ApplicationRecord))
expect(described_class.schemas_metrics).to receive(:increment)
- .with({ ci_dedicated_primary_connection: anything }.merge(expectations)).and_call_original
+ .with(expectations).and_call_original
process_sql(model, sql)
end
diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb
index 025cf05424e..064613074cd 100644
--- a/spec/lib/gitlab/database_spec.rb
+++ b/spec/lib/gitlab/database_spec.rb
@@ -160,13 +160,15 @@ RSpec.describe Gitlab::Database do
end
end
- context 'when the connection is LoadBalancing::ConnectionProxy' do
- it 'returns primary_db_config' do
- lb_config = ::Gitlab::Database::LoadBalancing::Configuration.new(ActiveRecord::Base)
- lb = ::Gitlab::Database::LoadBalancing::LoadBalancer.new(lb_config)
- proxy = ::Gitlab::Database::LoadBalancing::ConnectionProxy.new(lb)
-
- expect(described_class.db_config_for_connection(proxy)).to eq(lb_config.primary_db_config)
+ context 'when the connection is LoadBalancing::ConnectionProxy', :database_replica do
+ it 'returns primary db config even if ambiguous queries default to replica' do
+ Gitlab::Database::LoadBalancing::Session.current.use_primary!
+ primary_config = described_class.db_config_for_connection(ActiveRecord::Base.connection)
+
+ Gitlab::Database::LoadBalancing::Session.clear_session
+ Gitlab::Database::LoadBalancing::Session.current.fallback_to_replicas_for_ambiguous_queries do
+ expect(described_class.db_config_for_connection(ActiveRecord::Base.connection)).to eq(primary_config)
+ end
end
end
@@ -223,9 +225,6 @@ RSpec.describe Gitlab::Database do
describe '.gitlab_schemas_for_connection' do
it 'does return a valid schema depending on a base model used', :request_store do
- # FF due to lib/gitlab/database/load_balancing/configuration.rb:92
- stub_feature_flags(force_no_sharing_primary_model: true)
-
expect(described_class.gitlab_schemas_for_connection(Project.connection)).to include(:gitlab_main, :gitlab_shared)
expect(described_class.gitlab_schemas_for_connection(Ci::Build.connection)).to include(:gitlab_ci, :gitlab_shared)
end
diff --git a/spec/lib/gitlab/mail_room/mail_room_spec.rb b/spec/lib/gitlab/mail_room/mail_room_spec.rb
index 12fb12ebd87..06a25be757e 100644
--- a/spec/lib/gitlab/mail_room/mail_room_spec.rb
+++ b/spec/lib/gitlab/mail_room/mail_room_spec.rb
@@ -303,6 +303,7 @@ RSpec.describe Gitlab::MailRoom do
delivery_method: 'postback',
delivery_options: {
delivery_url: "http://gitlab.example/api/v4/internal/mail_room/incoming_email",
+ content_type: "text/plain",
jwt_auth_header: Gitlab::MailRoom::INTERNAL_API_REQUEST_HEADER,
jwt_issuer: Gitlab::MailRoom::INTERNAL_API_REQUEST_JWT_ISSUER,
jwt_algorithm: 'HS256',
@@ -316,6 +317,7 @@ RSpec.describe Gitlab::MailRoom do
delivery_method: 'postback',
delivery_options: {
delivery_url: "http://gitlab.example/api/v4/internal/mail_room/service_desk_email",
+ content_type: "text/plain",
jwt_auth_header: Gitlab::MailRoom::INTERNAL_API_REQUEST_HEADER,
jwt_issuer: Gitlab::MailRoom::INTERNAL_API_REQUEST_JWT_ISSUER,
jwt_algorithm: 'HS256',
diff --git a/spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb
index c88d8c17eac..57790ad78a8 100644
--- a/spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb
+++ b/spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb
@@ -66,7 +66,7 @@ RSpec.describe Gitlab::Metrics::Samplers::DatabaseSampler do
let(:main_replica_host) { main_load_balancer.host }
let(:ci_load_balancer) { double(:load_balancer, host_list: ci_host_list, configuration: configuration) }
- let(:configuration) { double(:configuration, primary_connection_specification_name: 'Ci::ApplicationRecord') }
+ let(:configuration) { double(:configuration, connection_specification_name: 'Ci::ApplicationRecord') }
let(:ci_host_list) { double(:host_list, hosts: [ci_replica_host]) }
let(:ci_replica_host) { double(:host, connection: ci_connection) }
let(:ci_connection) { double(:connection, pool: Ci::ApplicationRecord.connection_pool) }
@@ -121,7 +121,7 @@ RSpec.describe Gitlab::Metrics::Samplers::DatabaseSampler do
let(:main_replica_host) { main_load_balancer.host }
let(:ci_load_balancer) { double(:load_balancer, host_list: ci_host_list, configuration: configuration) }
- let(:configuration) { double(:configuration, primary_connection_specification_name: 'Ci::ApplicationRecord') }
+ let(:configuration) { double(:configuration, connection_specification_name: 'Ci::ApplicationRecord') }
let(:ci_host_list) { double(:host_list, hosts: [ci_replica_host]) }
let(:ci_replica_host) { double(:host, connection: ci_connection) }
let(:ci_connection) { double(:connection, pool: Ci::ApplicationRecord.connection_pool) }
diff --git a/spec/lib/marginalia_spec.rb b/spec/lib/marginalia_spec.rb
index 53048ae2e6b..693b7bd45c9 100644
--- a/spec/lib/marginalia_spec.rb
+++ b/spec/lib/marginalia_spec.rb
@@ -59,7 +59,7 @@ RSpec.describe 'Marginalia spec' do
"application" => "test",
"endpoint_id" => "MarginaliaTestController#first_user",
"correlation_id" => correlation_id,
- "db_config_name" => ENV['GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci'] == 'main' ? 'main' : 'ci'
+ "db_config_name" => 'ci'
}
end
diff --git a/spec/migrations/20220523171107_drop_deploy_tokens_token_column_spec.rb b/spec/migrations/20220523171107_drop_deploy_tokens_token_column_spec.rb
new file mode 100644
index 00000000000..78df6f5fc35
--- /dev/null
+++ b/spec/migrations/20220523171107_drop_deploy_tokens_token_column_spec.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe DropDeployTokensTokenColumn do
+ let(:deploy_tokens) { table(:deploy_tokens) }
+
+ it 'correctly migrates up and down' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(deploy_tokens.column_names).to include('token')
+ }
+
+ migration.after -> {
+ deploy_tokens.reset_column_information
+
+ expect(deploy_tokens.column_names).not_to include('token')
+ }
+ end
+ end
+end
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index f252c4e2e96..4136e98780b 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -1394,81 +1394,68 @@ RSpec.describe MergeRequest, factory_default: :keep do
end
end
- [
- 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', ' [WIP] WIP: [WIP] WIP:',
- "WIP ", "(WIP)",
- "draft", "Draft", "Draft -", "draft - ", "Draft ", "draft "
- ].each do |draft_prefix|
- it "doesn't detect '#{draft_prefix}' at the start of the title as a draft" do
- subject.title = "#{draft_prefix}#{subject.title}"
+ context "returns false" do
+ # We have removed support for variations of "WIP", and additionally need
+ # to test unsupported variations of "Draft" that we have seen users
+ # attempt.
+ #
+ [
+ 'WIP:', 'WIP: ', '[WIP]', '[WIP] ', ' [WIP] WIP: [WIP] WIP:',
+ "WIP ", "(WIP)",
+ "draft", "Draft", "Draft -", "draft - ", "Draft ", "draft "
+ ].each do |trigger|
+ it "when '#{trigger}' prefixes the title" do
+ subject.title = "#{trigger}#{subject.title}"
- expect(subject.work_in_progress?).to eq false
+ expect(subject.draft?).to eq false
+ end
end
- end
-
- it "doesn't detect merge request title just saying 'wip'" do
- subject.title = "wip"
-
- expect(subject.work_in_progress?).to eq false
- end
- it "does not detect merge request title just saying 'draft'" do
- subject.title = "draft"
+ ["WIP", "Draft"].each do |trigger| # rubocop:disable Style/WordArray
+ it "when merge request title is simply '#{trigger}'" do
+ subject.title = trigger
- expect(subject.work_in_progress?).to eq false
- end
-
- it 'does not detect WIP in the middle of the title' do
- subject.title = 'Something with WIP in the middle'
-
- expect(subject.work_in_progress?).to eq false
- end
-
- it 'does not detect Draft in the middle of the title' do
- subject.title = 'Something with Draft in the middle'
+ expect(subject.draft?).to eq false
+ end
- expect(subject.work_in_progress?).to eq false
- end
+ it "when #{trigger} is in the middle of the title" do
+ subject.title = "Something with #{trigger} in the middle"
- it 'does not detect Draft: in the middle of the title' do
- subject.title = 'Something with Draft: in the middle'
+ expect(subject.draft?).to eq false
+ end
- expect(subject.work_in_progress?).to eq false
- end
+ it "when #{trigger} is at the end of the title" do
+ subject.title = "Something ends with #{trigger}"
- it 'does not detect WIP at the end of the title' do
- subject.title = 'Something ends with WIP'
+ expect(subject.draft?).to eq false
+ end
- expect(subject.work_in_progress?).to eq false
- end
+ it "when title contains words starting with #{trigger}" do
+ subject.title = "#{trigger}foo #{subject.title}"
- it 'does not detect Draft at the end of the title' do
- subject.title = 'Something ends with Draft'
+ expect(subject.draft?).to eq false
+ end
- expect(subject.work_in_progress?).to eq false
- end
+ it "when title contains words containing with #{trigger}" do
+ subject.title = "Foo#{trigger}Bar #{subject.title}"
- it "doesn't detect WIP for words starting with WIP" do
- subject.title = "Wipwap #{subject.title}"
- expect(subject.work_in_progress?).to eq false
- end
+ expect(subject.draft?).to eq false
+ end
+ end
- it "doesn't detect WIP for words containing with WIP" do
- subject.title = "WupWipwap #{subject.title}"
- expect(subject.work_in_progress?).to eq false
- end
+ it 'when Draft: in the middle of the title' do
+ subject.title = 'Something with Draft: in the middle'
- it "doesn't detect draft for words containing with draft" do
- subject.title = "Drafting #{subject.title}"
- expect(subject.work_in_progress?).to eq false
- end
+ expect(subject.draft?).to eq false
+ end
- it "doesn't detect WIP by default" do
- expect(subject.work_in_progress?).to eq false
- end
+ it "when the title does not contain draft" do
+ expect(subject.draft?).to eq false
+ end
- it "is aliased to #draft?" do
- expect(subject.method(:work_in_progress?)).to eq(subject.method(:draft?))
+ it "is aliased to #draft?" do
+ expect(subject.method(:work_in_progress?)).to eq(subject.method(:draft?))
+ end
end
end
diff --git a/spec/requests/api/internal/mail_room_spec.rb b/spec/requests/api/internal/mail_room_spec.rb
index 2a056f21bc8..a0a9c1f9cb3 100644
--- a/spec/requests/api/internal/mail_room_spec.rb
+++ b/spec/requests/api/internal/mail_room_spec.rb
@@ -215,5 +215,29 @@ RSpec.describe API::Internal::MailRoom do
expect(job).to match a_hash_including('args' => [encoded_email_content])
end
end
+
+ context 'handle text/plain request content type' do
+ let(:auth_headers) do
+ jwt_token = JWT.encode(auth_payload, incoming_email_secret, 'HS256')
+ {
+ Gitlab::MailRoom::INTERNAL_API_REQUEST_HEADER => jwt_token,
+ 'Content-Type' => 'text/plain'
+ }
+ end
+
+ it 'schedules a EmailReceiverWorker job with email content encoded to utf-8 forcefully' do
+ Sidekiq::Testing.fake! do
+ expect do
+ post api("/internal/mail_room/incoming_email"), headers: auth_headers, params: email_content
+ end.to change { EmailReceiverWorker.jobs.size }.by(1)
+ end
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response.content_type).to eql('application/json')
+
+ job = EmailReceiverWorker.jobs.last
+ expect(job).to match a_hash_including('args' => [email_content])
+ end
+ end
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index a8b5908c57e..6c9a11587d3 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -256,16 +256,6 @@ RSpec.configure do |config|
end
config.around do |example|
- if example.metadata.fetch(:stub_feature_flags, true)
- # It doesn't make sense for this to default to enabled as we only plan to
- # use this temporarily to override an environment variable but eventually
- # we'll just use the environment variable value when we've completed the
- # gradual rollout. This stub must happen in around block as there are other
- # around blocks in tests that will run before this and get the wrong
- # database connection.
- stub_feature_flags(force_no_sharing_primary_model: false)
- end
-
example.run
end