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
cf86abe0
Commit
cf86abe0
authored
Dec 15, 2021
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for all query analyzers improvements
Ensures that each fixed case is well documented and tested.
parent
f1f49028
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
spec/lib/gitlab/database/query_analyzer_spec.rb
spec/lib/gitlab/database/query_analyzer_spec.rb
+9
-0
spec/lib/gitlab/database/query_analyzers/prevent_cross_database_modification_spec.rb
...ery_analyzers/prevent_cross_database_modification_spec.rb
+45
-0
No files found.
spec/lib/gitlab/database/query_analyzer_spec.rb
View file @
cf86abe0
...
...
@@ -128,11 +128,20 @@ RSpec.describe Gitlab::Database::QueryAnalyzer, query_analyzers: false do
it
'does not call analyze on suppressed analyzers'
do
expect
(
analyzer
).
to
receive
(
:suppressed?
).
and_return
(
true
)
expect
(
analyzer
).
to
receive
(
:requires_tracking?
).
and_return
(
false
)
expect
(
analyzer
).
not_to
receive
(
:analyze
)
expect
{
process_sql
(
"SELECT 1 FROM projects"
)
}.
not_to
raise_error
end
it
'does call analyze on suppressed analyzers if some queries require tracking'
do
expect
(
analyzer
).
to
receive
(
:suppressed?
).
and_return
(
true
)
expect
(
analyzer
).
to
receive
(
:requires_tracking?
).
and_return
(
true
)
expect
(
analyzer
).
to
receive
(
:analyze
)
expect
{
process_sql
(
"SELECT 1 FROM projects"
)
}.
not_to
raise_error
end
def
process_sql
(
sql
)
described_class
.
instance
.
within
do
ApplicationRecord
.
load_balancer
.
read_write
do
|
connection
|
...
...
spec/lib/gitlab/database/query_analyzers/prevent_cross_database_modification_spec.rb
View file @
cf86abe0
...
...
@@ -181,4 +181,49 @@ RSpec.describe Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModificatio
end
.
to
raise_error
/Cross-database data modification.*The gitlab_schema was undefined/
end
end
context
'when execution is rescued with StandardError'
do
it
'raises cross-database data modification exception'
do
expect
do
Project
.
transaction
do
project
.
touch
project
.
connection
.
execute
(
'UPDATE foo_bars_undefined_table SET a=1 WHERE id = -1'
)
end
rescue
StandardError
# Ensures that standard rescue does not silence errors
end
.
to
raise_error
/Cross-database data modification.*The gitlab_schema was undefined/
end
end
context
'when uniquiness validation is tested'
,
type: :model
do
subject
{
build
(
:ci_variable
)
}
it
'does not raise exceptions'
do
expect
do
is_expected
.
to
validate_uniqueness_of
(
:key
).
scoped_to
(
:project_id
,
:environment_scope
).
with_message
(
/\(\w+\) has already been taken/
)
end
.
not_to
raise_error
end
end
context
'when doing rollback in a suppressed block'
do
it
'does not raise misaligned transactions exception'
do
expect
do
# This is non-materialised transaction:
# 1. the transaction will be open on a write (project.touch) (in a suppressed block)
# 2. the rescue will be handled outside of suppressed block
#
# This will create misaligned boundaries since BEGIN
# of transaction will be executed within a suppressed block
Project
.
transaction
do
described_class
.
with_suppressed
do
project
.
touch
raise
'force rollback'
end
# the ensure of `.transaction` executes `ROLLBACK TO SAVEPOINT`
end
end
.
to
raise_error
/force rollback/
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