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
87843a1a
Commit
87843a1a
authored
Mar 18, 2021
by
Quang-Minh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fulfill the tests for transaction instrumentations
parent
8ff69500
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
125 additions
and
45 deletions
+125
-45
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
+125
-45
No files found.
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
View file @
87843a1a
...
@@ -8,6 +8,85 @@ RSpec.describe Gitlab::Metrics::Subscribers::ActiveRecord do
...
@@ -8,6 +8,85 @@ RSpec.describe Gitlab::Metrics::Subscribers::ActiveRecord do
let
(
:env
)
{
{}
}
let
(
:env
)
{
{}
}
let
(
:subscriber
)
{
described_class
.
new
}
let
(
:subscriber
)
{
described_class
.
new
}
let
(
:connection
)
{
double
(
:connection
)
}
let
(
:connection
)
{
double
(
:connection
)
}
describe
'#transaction'
do
let
(
:web_transaction
)
{
double
(
'Gitlab::Metrics::WebTransaction'
)
}
let
(
:background_transaction
)
{
double
(
'Gitlab::Metrics::WebTransaction'
)
}
let
(
:event
)
do
double
(
:event
,
name:
'transaction.active_record'
,
duration:
230
,
payload:
{
connection:
connection
}
)
end
before
do
allow
(
background_transaction
).
to
receive
(
:observe
)
allow
(
web_transaction
).
to
receive
(
:observe
)
end
context
'when both web and background transaction are available'
do
before
do
allow
(
::
Gitlab
::
Metrics
::
WebTransaction
).
to
receive
(
:current
)
.
and_return
(
web_transaction
)
allow
(
::
Gitlab
::
Metrics
::
BackgroundTransaction
).
to
receive
(
:current
)
.
and_return
(
background_transaction
)
end
it
'captures the metrics for web only'
do
expect
(
web_transaction
).
to
receive
(
:observe
).
with
(
:gitlab_database_transaction_seconds
,
0.23
)
expect
(
background_transaction
).
not_to
receive
(
:observe
)
expect
(
background_transaction
).
not_to
receive
(
:increment
)
subscriber
.
transaction
(
event
)
end
end
context
'when web transaction is available'
do
let
(
:web_transaction
)
{
double
(
'Gitlab::Metrics::WebTransaction'
)
}
before
do
allow
(
::
Gitlab
::
Metrics
::
WebTransaction
).
to
receive
(
:current
)
.
and_return
(
web_transaction
)
allow
(
::
Gitlab
::
Metrics
::
BackgroundTransaction
).
to
receive
(
:current
)
.
and_return
(
nil
)
end
it
'captures the metrics for web only'
do
expect
(
web_transaction
).
to
receive
(
:observe
).
with
(
:gitlab_database_transaction_seconds
,
0.23
)
expect
(
background_transaction
).
not_to
receive
(
:observe
)
expect
(
background_transaction
).
not_to
receive
(
:increment
)
subscriber
.
transaction
(
event
)
end
end
context
'when background transaction is available'
do
let
(
:background_transaction
)
{
double
(
'Gitlab::Metrics::BackgroundTransaction'
)
}
before
do
allow
(
::
Gitlab
::
Metrics
::
WebTransaction
).
to
receive
(
:current
)
.
and_return
(
nil
)
allow
(
::
Gitlab
::
Metrics
::
BackgroundTransaction
).
to
receive
(
:current
)
.
and_return
(
background_transaction
)
end
it
'captures the metrics for web only'
do
expect
(
background_transaction
).
to
receive
(
:observe
).
with
(
:gitlab_database_transaction_seconds
,
0.23
)
expect
(
web_transaction
).
not_to
receive
(
:observe
)
expect
(
web_transaction
).
not_to
receive
(
:increment
)
subscriber
.
transaction
(
event
)
end
end
end
describe
'#sql'
do
let
(
:payload
)
{
{
sql:
'SELECT * FROM users WHERE id = 10'
,
connection:
connection
}
}
let
(
:payload
)
{
{
sql:
'SELECT * FROM users WHERE id = 10'
,
connection:
connection
}
}
let
(
:event
)
do
let
(
:event
)
do
...
@@ -69,4 +148,5 @@ RSpec.describe Gitlab::Metrics::Subscribers::ActiveRecord do
...
@@ -69,4 +148,5 @@ RSpec.describe Gitlab::Metrics::Subscribers::ActiveRecord do
it_behaves_like
'track generic sql events'
it_behaves_like
'track generic sql events'
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