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>2020-04-30 03:09:37 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-30 03:09:37 +0300
commit0ec841b7f902243b832f11b352f215bd93bc680b (patch)
treeefc80df932176a4d9e99377acf720fcdd5f2bf0a /spec
parent82f5f2485b37ea938d11181f3e05ddf35ab1959e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/metrics/users_starred_dasboards.rb9
-rw-r--r--spec/features/projects/navbar_spec.rb2
-rw-r--r--spec/javascripts/line_highlighter_spec.js7
-rw-r--r--spec/lib/gitlab/exclusive_lease_helpers_spec.rb16
-rw-r--r--spec/lib/gitlab/import_export/all_models.yml1
-rw-r--r--spec/models/metrics/users_starred_dashboard_spec.rb20
-rw-r--r--spec/models/project_spec.rb1
-rw-r--r--spec/models/user_spec.rb1
-rw-r--r--spec/support/helpers/concurrent_helpers.rb40
-rw-r--r--spec/support/renameable_upload.rb15
10 files changed, 106 insertions, 6 deletions
diff --git a/spec/factories/metrics/users_starred_dasboards.rb b/spec/factories/metrics/users_starred_dasboards.rb
new file mode 100644
index 00000000000..06fe7735e9a
--- /dev/null
+++ b/spec/factories/metrics/users_starred_dasboards.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :metrics_users_starred_dashboard, class: '::Metrics::UsersStarredDashboard' do
+ dashboard_path { "custom_dashboard.yml" }
+ user
+ project
+ end
+end
diff --git a/spec/features/projects/navbar_spec.rb b/spec/features/projects/navbar_spec.rb
index 9dfdaf54a2f..f36ee3f1a44 100644
--- a/spec/features/projects/navbar_spec.rb
+++ b/spec/features/projects/navbar_spec.rb
@@ -12,6 +12,8 @@ describe 'Project navbar' do
let_it_be(:project) { create(:project, :repository) }
before do
+ stub_licensed_features(service_desk: false)
+
project.add_maintainer(user)
sign_in(user)
end
diff --git a/spec/javascripts/line_highlighter_spec.js b/spec/javascripts/line_highlighter_spec.js
index 661d99197b7..bedab0fd003 100644
--- a/spec/javascripts/line_highlighter_spec.js
+++ b/spec/javascripts/line_highlighter_spec.js
@@ -1,4 +1,4 @@
-/* eslint-disable no-else-return, dot-notation, no-return-assign, no-new, no-underscore-dangle */
+/* eslint-disable dot-notation, no-return-assign, no-new, no-underscore-dangle */
import $ from 'jquery';
import LineHighlighter from '~/line_highlighter';
@@ -8,10 +8,9 @@ describe('LineHighlighter', function() {
const clickLine = function(number, eventData = {}) {
if ($.isEmptyObject(eventData)) {
return $(`#L${number}`).click();
- } else {
- const e = $.Event('click', eventData);
- return $(`#L${number}`).trigger(e);
}
+ const e = $.Event('click', eventData);
+ return $(`#L${number}`).trigger(e);
};
beforeEach(function() {
loadFixtures('static/line_highlighter.html');
diff --git a/spec/lib/gitlab/exclusive_lease_helpers_spec.rb b/spec/lib/gitlab/exclusive_lease_helpers_spec.rb
index 747fe369c78..065468f6b06 100644
--- a/spec/lib/gitlab/exclusive_lease_helpers_spec.rb
+++ b/spec/lib/gitlab/exclusive_lease_helpers_spec.rb
@@ -82,10 +82,22 @@ describe Gitlab::ExclusiveLeaseHelpers, :clean_gitlab_redis_shared_state do
end
context 'when sleep second is specified' do
- let(:options) { { retries: 0, sleep_sec: 0.05.seconds } }
+ let(:options) { { retries: 1, sleep_sec: 0.05.seconds } }
it 'receives the specified argument' do
- expect(class_instance).to receive(:sleep).with(0.05.seconds).once
+ expect(class_instance).to receive(:sleep).with(0.05.seconds).twice
+
+ expect { subject }.to raise_error('Failed to obtain a lock')
+ end
+ end
+
+ context 'when sleep second is specified as a lambda' do
+ let(:options) { { retries: 2, sleep_sec: ->(num) { 0.1 + num } } }
+
+ it 'receives the specified argument' do
+ expect(class_instance).to receive(:sleep).with(1.1.seconds).once
+ expect(class_instance).to receive(:sleep).with(2.1.seconds).once
+ expect(class_instance).to receive(:sleep).with(3.1.seconds).once
expect { subject }.to raise_error('Failed to obtain a lock')
end
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml
index fde8ed5c1ce..562351f8fb9 100644
--- a/spec/lib/gitlab/import_export/all_models.yml
+++ b/spec/lib/gitlab/import_export/all_models.yml
@@ -487,6 +487,7 @@ project:
- daily_report_results
- jira_imports
- compliance_framework_setting
+- metrics_users_starred_dashboards
- alert_management_alerts
award_emoji:
- awardable
diff --git a/spec/models/metrics/users_starred_dashboard_spec.rb b/spec/models/metrics/users_starred_dashboard_spec.rb
new file mode 100644
index 00000000000..0823027efdb
--- /dev/null
+++ b/spec/models/metrics/users_starred_dashboard_spec.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Metrics::UsersStarredDashboard do
+ describe 'associations' do
+ it { is_expected.to belong_to(:project).inverse_of(:metrics_users_starred_dashboards) }
+ it { is_expected.to belong_to(:user).inverse_of(:metrics_users_starred_dashboards) }
+ end
+
+ describe 'validation' do
+ subject { build(:metrics_users_starred_dashboard) }
+
+ it { is_expected.to validate_presence_of(:user_id) }
+ it { is_expected.to validate_presence_of(:project_id) }
+ it { is_expected.to validate_presence_of(:dashboard_path) }
+ it { is_expected.to validate_length_of(:dashboard_path).is_at_most(255) }
+ it { is_expected.to validate_uniqueness_of(:dashboard_path).scoped_to(%i[user_id project_id]) }
+ end
+end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 05ea2912cb7..18f77592cd6 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -113,6 +113,7 @@ describe Project do
it { is_expected.to have_many(:self_managed_prometheus_alert_events) }
it { is_expected.to have_many(:alert_management_alerts) }
it { is_expected.to have_many(:jira_imports) }
+ it { is_expected.to have_many(:metrics_users_starred_dashboards).inverse_of(:project) }
it_behaves_like 'model with repository' do
let_it_be(:container) { create(:project, :repository, path: 'somewhere') }
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 10da73104a4..b05311814d0 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -54,6 +54,7 @@ describe User, :do_not_mock_admin_mode do
it { is_expected.to have_many(:reported_abuse_reports).dependent(:destroy).class_name('AbuseReport') }
it { is_expected.to have_many(:custom_attributes).class_name('UserCustomAttribute') }
it { is_expected.to have_many(:releases).dependent(:nullify) }
+ it { is_expected.to have_many(:metrics_users_starred_dashboards).inverse_of(:user) }
describe "#bio" do
it 'syncs bio with `user_details.bio` on create' do
diff --git a/spec/support/helpers/concurrent_helpers.rb b/spec/support/helpers/concurrent_helpers.rb
new file mode 100644
index 00000000000..4eecc2133e7
--- /dev/null
+++ b/spec/support/helpers/concurrent_helpers.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+module ConcurrentHelpers
+ Cancelled = Class.new(StandardError)
+
+ # To test for contention, we may need to run some actions in parallel. This
+ # helper takes an array of blocks and schedules them all on different threads
+ # in a fixed-size thread pool.
+ #
+ # @param [Array[Proc]] blocks
+ # @param [Integer] task_wait_time: time to wait for each task (upper bound on
+ # reasonable task execution time)
+ # @param [Integer] max_concurrency: maximum number of tasks to run at once
+ #
+ def run_parallel(blocks, task_wait_time: 20.seconds, max_concurrency: Concurrent.processor_count - 1)
+ thread_pool = Concurrent::FixedThreadPool.new(
+ [2, max_concurrency].max, { max_queue: blocks.size }
+ )
+ opts = { executor: thread_pool }
+
+ error = Concurrent::MVar.new
+
+ blocks.map { |block| Concurrent::Future.execute(opts, &block) }.each do |future|
+ future.wait(task_wait_time)
+
+ if future.complete?
+ error.put(future.reason) if future.reason && error.empty?
+ else
+ future.cancel
+ error.put(Cancelled.new) if error.empty?
+ end
+ end
+
+ raise error.take if error.full?
+ ensure
+ thread_pool.shutdown
+ thread_pool.wait_for_termination(10)
+ thread_pool.kill if thread_pool.running?
+ end
+end
diff --git a/spec/support/renameable_upload.rb b/spec/support/renameable_upload.rb
new file mode 100644
index 00000000000..f7f00181605
--- /dev/null
+++ b/spec/support/renameable_upload.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class RenameableUpload < SimpleDelegator
+ attr_accessor :original_filename
+
+ # Get a fixture file with a new unique name, and the same extension
+ def self.unique_file(name)
+ upload = new(fixture_file_upload("spec/fixtures/#{name}"))
+ ext = File.extname(name)
+ new_name = File.basename(FactoryBot.generate(:filename), '.*')
+ upload.original_filename = new_name + ext
+
+ upload
+ end
+end