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
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/highlight_spec.rb')
-rw-r--r--spec/lib/gitlab/highlight_spec.rb76
1 files changed, 11 insertions, 65 deletions
diff --git a/spec/lib/gitlab/highlight_spec.rb b/spec/lib/gitlab/highlight_spec.rb
index 1f06019c929..65d8c59fea7 100644
--- a/spec/lib/gitlab/highlight_spec.rb
+++ b/spec/lib/gitlab/highlight_spec.rb
@@ -53,10 +53,6 @@ RSpec.describe Gitlab::Highlight do
stub_config(extra: { 'maximum_text_highlight_size_kilobytes' => 0.0001 } ) # 1.024 bytes
end
- it 'increments the metric for oversized files' do
- expect { result }.to change { over_highlight_size_limit('file size: 0.0001') }.by(1)
- end
-
it 'returns plain version for long content' do
expect(result).to eq(%[<span id="LC1" class="line" lang="">(make-pathname :defaults name</span>\n<span id="LC2" class="line" lang="">:type "assem")</span>])
end
@@ -126,79 +122,29 @@ RSpec.describe Gitlab::Highlight do
end
context 'timeout' do
- subject { described_class.new('file.name', 'Contents') }
+ subject(:highlight) { described_class.new('file.rb', 'begin', language: 'ruby').highlight('Content') }
it 'utilizes timeout for web' do
expect(Timeout).to receive(:timeout).with(described_class::TIMEOUT_FOREGROUND).and_call_original
- subject.highlight("Content")
+ highlight
end
- it 'utilizes longer timeout for sidekiq' do
- allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true)
- expect(Timeout).to receive(:timeout).with(described_class::TIMEOUT_BACKGROUND).and_call_original
+ it 'falls back to plaintext on timeout' do
+ allow(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
+ expect(Timeout).to receive(:timeout).and_raise(Timeout::Error)
- subject.highlight("Content")
- end
- end
+ expect(Rouge::Lexers::PlainText).to receive(:lex).and_call_original
- describe 'highlight timeouts' do
- let(:result) { described_class.highlight(file_name, content, language: "ruby") }
-
- context 'when there is an attempt' do
- it "increments the attempt counter with a defined language" do
- expect { result }.to change { highlight_attempt_total("ruby") }
- end
-
- it "increments the attempt counter with an undefined language" do
- expect do
- described_class.highlight(file_name, content)
- end.to change { highlight_attempt_total("undefined") }
- end
+ highlight
end
- context 'when there is a timeout error while highlighting' do
- before do
- allow(Timeout).to receive(:timeout).twice.and_raise(Timeout::Error)
- # This is done twice because it's rescued first and then
- # calls the original exception
- end
-
- it "increments the foreground counter if it's in the foreground" do
- expect { result }
- .to raise_error(Timeout::Error)
- .and change { highlight_timeout_total('foreground') }.by(1)
- .and not_change { highlight_timeout_total('background') }
- end
-
- it "increments the background counter if it's in the background" do
- allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true)
+ it 'utilizes longer timeout for sidekiq' do
+ allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true)
+ expect(Timeout).to receive(:timeout).with(described_class::TIMEOUT_BACKGROUND).and_call_original
- expect { result }
- .to raise_error(Timeout::Error)
- .and change { highlight_timeout_total('background') }.by(1)
- .and not_change { highlight_timeout_total('foreground') }
- end
+ highlight
end
end
end
-
- def highlight_timeout_total(source)
- Gitlab::Metrics
- .counter(:highlight_timeout, 'Counts the times highlights have timed out')
- .get(source: source)
- end
-
- def highlight_attempt_total(source)
- Gitlab::Metrics
- .counter(:file_highlighting_attempt, 'Counts the times highlighting has been attempted on a file')
- .get(source: source)
- end
-
- def over_highlight_size_limit(source)
- Gitlab::Metrics
- .counter(:over_highlight_size_limit,
- 'Count the times text has been over the highlight size limit')
- .get(source: source)
- end
end