Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d580bea6
Commit
d580bea6
authored
Apr 13, 2022
by
Eduardo Bonet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds tests for counter increment
parent
ce1bf1ff
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
11 deletions
+36
-11
lib/gitlab/diff/custom_diff.rb
lib/gitlab/diff/custom_diff.rb
+5
-1
spec/lib/gitlab/diff/custom_diff_spec.rb
spec/lib/gitlab/diff/custom_diff_spec.rb
+31
-10
No files found.
lib/gitlab/diff/custom_diff.rb
View file @
d580bea6
...
@@ -21,7 +21,7 @@ module Gitlab
...
@@ -21,7 +21,7 @@ module Gitlab
end
end
end
end
rescue
Timeout
::
Error
=>
e
rescue
Timeout
::
Error
=>
e
rendered_timeout
.
increment
(
source:
Gitlab
::
Runtime
.
sidekiq?
?
BACKGROUND_EXECUTION
:
FOREGROUND_EXECUTION
)
rendered_timeout
.
increment
(
source:
execution_source
)
log_event
(
LOG_IPYNBDIFF_TIMEOUT
,
e
)
log_event
(
LOG_IPYNBDIFF_TIMEOUT
,
e
)
rescue
IpynbDiff
::
InvalidNotebookError
,
IpynbDiff
::
InvalidTokenError
=>
e
rescue
IpynbDiff
::
InvalidNotebookError
,
IpynbDiff
::
InvalidTokenError
=>
e
log_event
(
LOG_IPYNBDIFF_INVALID
,
e
)
log_event
(
LOG_IPYNBDIFF_INVALID
,
e
)
...
@@ -74,6 +74,10 @@ module Gitlab
...
@@ -74,6 +74,10 @@ module Gitlab
Gitlab
::
Runtime
.
sidekiq?
?
RENDERED_TIMEOUT_BACKGROUND
:
RENDERED_TIMEOUT_FOREGROUND
Gitlab
::
Runtime
.
sidekiq?
?
RENDERED_TIMEOUT_BACKGROUND
:
RENDERED_TIMEOUT_FOREGROUND
end
end
def
execution_source
Gitlab
::
Runtime
.
sidekiq?
?
BACKGROUND_EXECUTION
:
FOREGROUND_EXECUTION
end
def
log_event
(
message
,
error
=
nil
)
def
log_event
(
message
,
error
=
nil
)
Gitlab
::
AppLogger
.
info
({
message:
message
})
Gitlab
::
AppLogger
.
info
({
message:
message
})
Gitlab
::
ErrorTracking
.
log_exception
(
error
)
if
error
Gitlab
::
ErrorTracking
.
log_exception
(
error
)
if
error
...
...
spec/lib/gitlab/diff/custom_diff_spec.rb
View file @
d580bea6
...
@@ -36,24 +36,45 @@ RSpec.describe Gitlab::Diff::CustomDiff do
...
@@ -36,24 +36,45 @@ RSpec.describe Gitlab::Diff::CustomDiff do
end
end
context
'timeout'
do
context
'timeout'
do
subject
{
described_class
.
preprocess_before_diff
(
ipynb_blob
.
path
,
nil
,
ipynb_blob
)
}
it
'falls back to nil on timeout'
do
allow
(
Gitlab
::
ErrorTracking
).
to
receive
(
:track_and_raise_for_dev_exception
)
expect
(
Timeout
).
to
receive
(
:timeout
).
and_raise
(
Timeout
::
Error
)
expect
(
subject
).
to
be_nil
end
context
'when in foreground'
do
it
'utilizes timeout for web'
do
it
'utilizes timeout for web'
do
expect
(
Timeout
).
to
receive
(
:timeout
).
with
(
described_class
::
RENDERED_TIMEOUT_FOREGROUND
).
and_call_original
expect
(
Timeout
).
to
receive
(
:timeout
).
with
(
described_class
::
RENDERED_TIMEOUT_FOREGROUND
).
and_call_original
expect
(
described_class
.
preprocess_before_diff
(
ipynb_blob
.
path
,
nil
,
ipynb_blob
)
).
not_to
include
(
'cells'
)
expect
(
subject
).
not_to
include
(
'cells'
)
end
end
it
'falls back to nil on timeout'
do
it
'increments metrics'
do
allow
(
Gitlab
::
ErrorTracking
).
to
receive
(
:track_and_raise_for_dev_exception
)
expect
(
Timeout
).
to
receive
(
:timeout
).
and_raise
(
Timeout
::
Error
)
expect
(
Timeout
).
to
receive
(
:timeout
).
and_raise
(
Timeout
::
Error
)
counter
=
Gitlab
::
Metrics
.
counter
(
:rendered_timeout
,
'desc'
)
expect
{
subject
}.
to
change
{
counter
.
get
(
source:
described_class
::
FOREGROUND_EXECUTION
)
}.
by
(
1
)
end
end
expect
(
described_class
.
preprocess_before_diff
(
ipynb_blob
.
path
,
nil
,
ipynb_blob
)).
to
be_nil
context
'when in background'
do
before
do
allow
(
Gitlab
::
Runtime
).
to
receive
(
:sidekiq?
).
and_return
(
true
)
end
end
it
'utilizes longer timeout for sidekiq'
do
it
'utilizes longer timeout for sidekiq'
do
allow
(
Gitlab
::
Runtime
).
to
receive
(
:sidekiq?
).
and_return
(
true
)
expect
(
Timeout
).
to
receive
(
:timeout
).
with
(
described_class
::
RENDERED_TIMEOUT_BACKGROUND
).
and_call_original
expect
(
Timeout
).
to
receive
(
:timeout
).
with
(
described_class
::
RENDERED_TIMEOUT_BACKGROUND
).
and_call_original
described_class
.
preprocess_before_diff
(
ipynb_blob
.
path
,
nil
,
ipynb_blob
)
expect
(
subject
).
not_to
include
(
'cells'
)
end
it
'increments metrics'
do
expect
(
Timeout
).
to
receive
(
:timeout
).
and_raise
(
Timeout
::
Error
)
counter
=
Gitlab
::
Metrics
.
counter
(
:rendered_timeout
,
'desc'
)
expect
{
subject
}.
to
change
{
counter
.
get
(
source:
described_class
::
BACKGROUND_EXECUTION
)
}.
by
(
1
)
end
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment