summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/highlight_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/highlight_spec.rb')
-rw-r--r--spec/lib/gitlab/highlight_spec.rb24
1 files changed, 21 insertions, 3 deletions
diff --git a/spec/lib/gitlab/highlight_spec.rb b/spec/lib/gitlab/highlight_spec.rb
index a5e4d37d306..1f06019c929 100644
--- a/spec/lib/gitlab/highlight_spec.rb
+++ b/spec/lib/gitlab/highlight_spec.rb
@@ -54,7 +54,7 @@ RSpec.describe Gitlab::Highlight do
end
it 'increments the metric for oversized files' do
- expect { result }.to change { over_highlight_size_limit('text highlighter') }.by(1)
+ expect { result }.to change { over_highlight_size_limit('file size: 0.0001') }.by(1)
end
it 'returns plain version for long content' do
@@ -143,9 +143,21 @@ RSpec.describe Gitlab::Highlight do
end
describe 'highlight timeouts' do
- context 'when there is a timeout error while highlighting' do
- let(:result) { described_class.highlight(file_name, content) }
+ 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
+ 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
@@ -177,6 +189,12 @@ RSpec.describe Gitlab::Highlight do
.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,