summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-04 12:07:52 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-04 12:07:52 +0000
commitc6c7437861bff9572747674095c4dfbdfbea4988 (patch)
tree237d1ed922193f19ae326923457344c082003788 /spec/lib/gitlab
parentd80f3cd75e700b6e62910865bfd36734644ffa89 (diff)
downloadgitlab-ce-c6c7437861bff9572747674095c4dfbdfbea4988.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/lograge/custom_options_spec.rb50
-rw-r--r--spec/lib/gitlab/sidekiq_queue_spec.rb9
-rw-r--r--spec/lib/gitlab/utils/json_size_estimator_spec.rb39
3 files changed, 90 insertions, 8 deletions
diff --git a/spec/lib/gitlab/lograge/custom_options_spec.rb b/spec/lib/gitlab/lograge/custom_options_spec.rb
new file mode 100644
index 00000000000..48d06283b7a
--- /dev/null
+++ b/spec/lib/gitlab/lograge/custom_options_spec.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Lograge::CustomOptions do
+ describe '.call' do
+ let(:params) do
+ {
+ 'controller' => 'ApplicationController',
+ 'action' => 'show',
+ 'format' => 'html',
+ 'a' => 'b'
+ }
+ end
+
+ let(:event) do
+ ActiveSupport::Notifications::Event.new(
+ 'test',
+ 1,
+ 2,
+ 'transaction_id',
+ { params: params, user_id: 'test' }
+ )
+ end
+
+ subject { described_class.call(event) }
+
+ it 'ignores some parameters' do
+ param_keys = subject[:params].map { |param| param[:key] }
+
+ expect(param_keys).not_to include(*described_class::IGNORE_PARAMS)
+ end
+
+ it 'formats the parameters' do
+ expect(subject[:params]).to eq([{ key: 'a', value: 'b' }])
+ end
+
+ it 'adds the current time' do
+ travel_to(5.days.ago) do
+ expected_time = Time.now.utc.iso8601(3)
+
+ expect(subject[:time]).to eq(expected_time)
+ end
+ end
+
+ it 'adds the user id' do
+ expect(subject[:user_id]).to eq('test')
+ end
+ end
+end
diff --git a/spec/lib/gitlab/sidekiq_queue_spec.rb b/spec/lib/gitlab/sidekiq_queue_spec.rb
index 7a4d47563b6..9516ea10511 100644
--- a/spec/lib/gitlab/sidekiq_queue_spec.rb
+++ b/spec/lib/gitlab/sidekiq_queue_spec.rb
@@ -31,14 +31,7 @@ describe Gitlab::SidekiqQueue do
context 'when the queue is not processed in time' do
before do
- calls = 0
-
- allow(sidekiq_queue).to receive(:job_matches?).and_wrap_original do |m, *args|
- raise Timeout::Error if calls > 0
-
- calls += 1
- m.call(*args)
- end
+ allow(Gitlab::Metrics::System).to receive(:monotonic_time).and_return(1, 2, 12)
end
it 'returns a non-completion flag, the number of jobs deleted, and the remaining queue size' do
diff --git a/spec/lib/gitlab/utils/json_size_estimator_spec.rb b/spec/lib/gitlab/utils/json_size_estimator_spec.rb
new file mode 100644
index 00000000000..ae24e25558a
--- /dev/null
+++ b/spec/lib/gitlab/utils/json_size_estimator_spec.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Utils::JsonSizeEstimator do
+ RSpec::Matchers.define :match_json_bytesize_of do |expected|
+ match do |actual|
+ actual == expected.to_json.bytesize
+ end
+ end
+
+ def estimate(object)
+ described_class.estimate(object)
+ end
+
+ [
+ [],
+ [[[[]]]],
+ [1, "str", 3.14, ["str", { a: -1 }]],
+ {},
+ { a: {} },
+ { a: { b: { c: [1, 2, 3], e: Time.now, f: nil } } },
+ { 100 => 500 },
+ { '狸' => '狸' },
+ nil
+ ].each do |example|
+ it { expect(estimate(example)).to match_json_bytesize_of(example) }
+ end
+
+ it 'calls #to_s on unknown object' do
+ klass = Class.new do
+ def to_s
+ 'hello'
+ end
+ end
+
+ expect(estimate(klass.new)).to match_json_bytesize_of(klass.new.to_s) # "hello"
+ end
+end