Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
10f0de42
Unverified
Commit
10f0de42
authored
1 year ago
by
Matt Jankowski
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Refactor race condition reblog service spec (#24526)
parent
b0800d60
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
spec/services/reblog_service_spec.rb
+17
-5
17 additions, 5 deletions
spec/services/reblog_service_spec.rb
with
17 additions
and
5 deletions
spec/services/reblog_service_spec.rb
+
17
−
5
View file @
10f0de42
...
...
@@ -35,13 +35,25 @@ RSpec.describe ReblogService, type: :service do
end
context
'when the reblogged status is discarded in the meantime'
do
let
(
:status
)
{
Fabricate
(
:status
,
account:
alice
,
visibility: :public
)
}
let
(
:status
)
{
Fabricate
(
:status
,
account:
alice
,
visibility: :public
,
text:
'discard-status-text'
)
}
# Add a callback to discard the status being reblogged after the
# validations pass but before the database commit is executed.
before
do
# Update the in-database attribute without reflecting the change in
# the object. This cannot simulate all race conditions, but it is
# pretty close.
Status
.
where
(
id:
status
.
id
).
update_all
(
deleted_at:
Time
.
now
.
utc
)
# rubocop:disable Rails/SkipsModelValidations
Status
.
class_eval
do
before_save
:discard_status
def
discard_status
Status
.
where
(
id:
reblog_of_id
)
.
where
(
text:
'discard-status-text'
)
.
update_all
(
deleted_at:
Time
.
now
.
utc
)
# rubocop:disable Rails/SkipsModelValidations
end
end
end
# Remove race condition simulating `discard_status` callback.
after
do
Status
.
_save_callbacks
.
delete
(
:discard_status
)
end
it
'raises an exception'
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment