Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable transactions in locking examples #18089

Conversation

jrafanie
Copy link
Member

@jrafanie jrafanie commented Oct 11, 2018

These tests are creating threads and explicit transactions to verify
when we're locked or not locked in the database. The Rails 5.1 release
notes mention that this type of behavior can cause a deadlock, which
we've seen with rails 5.1, and to instead disable transactional tests.

From the rails 5.1 release notes:

"Transactional tests now wrap all Active Record connections in database
transactions.

When a test spawns additional threads, and those threads obtain database
connections, those connections are now handled specially:

The threads will share a single connection, which is inside the managed
transaction. This ensures all threads see the database in the same
state, ignoring the outermost transaction. Previously, such additional
connections were unable to see the fixture rows, for example.

When a thread enters a nested transaction, it will temporarily obtain
exclusive use of the connection, to maintain isolation.

If your tests currently rely on obtaining a separate,
outside-of-transaction, connection in a spawned thread, you'll need to
switch to more explicit connection management.

If your tests spawn threads and those threads interact while also using
explicit database transactions, this change may introduce a deadlock.

The easy way to opt out of this new behavior is to disable transactional
tests on any test cases it affects."

https://guides.rubyonrails.org/5_1_release_notes.html

@@ -1,16 +1,15 @@
require "concurrent/atomic/event"

describe VmdbDatabaseConnection do
before do
@db = FactoryGirl.create(:vmdb_database)
Copy link
Member Author

@jrafanie jrafanie Oct 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay, this isn't needed and is actually a problem now that I disabled transactions for these examples.

@jrafanie
Copy link
Member Author

Enjoy my 📖 @NickLaMuro ... although I lifted it from rails' release notes..

Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought that might make this a bit cleaner. I would need to test it out before saying it works or not.

spec/models/vmdb_database_connection_spec.rb Show resolved Hide resolved
These tests are creating threads and explicit transactions to verify
when we're locked or not locked in the database.  The Rails 5.1 release
notes mention that this type of behavior can cause a deadlock, which
we've seen with rails 5.1, and to instead disable transactional tests.

From the rails 5.1 release notes:

Transactional tests now wrap all Active Record connections in database
transactions.

When a test spawns additional threads, and those threads obtain database
connections, those connections are now handled specially:

The threads will share a single connection, which is inside the managed
transaction. This ensures all threads see the database in the same
state, ignoring the outermost transaction. Previously, such additional
connections were unable to see the fixture rows, for example.

When a thread enters a nested transaction, it will temporarily obtain
exclusive use of the connection, to maintain isolation.

If your tests currently rely on obtaining a separate,
outside-of-transaction, connection in a spawned thread, you'll need to
switch to more explicit connection management.

If your tests spawn threads and those threads interact while also using
explicit database transactions, this change may introduce a deadlock.

The easy way to opt out of this new behavior is to disable transactional
tests on any test cases it affects.

https://guides.rubyonrails.org/5_1_release_notes.html
@jrafanie jrafanie force-pushed the disable_transactional_tests_for_locking_tests_to_avoid_deadlock_on_5_1 branch from 32c7c4a to ff6808b Compare October 15, 2018 20:25
@miq-bot
Copy link
Member

miq-bot commented Oct 15, 2018

Checked commit jrafanie@ff6808b with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🏆

Copy link
Member

@NickLaMuro NickLaMuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, and you got that sweet "net negative" badge in lines added to boot!

@jrafanie
Copy link
Member Author

Looks good to me, and you got that sweet "net negative" badge in lines added to boot!

thanks to @NickLaMuro's research... 🙇

@kbrock kbrock merged commit 80d8f78 into ManageIQ:master Oct 16, 2018
@kbrock kbrock added this to the Sprint 97 Ending Oct 22, 2018 milestone Oct 16, 2018
@kbrock kbrock self-assigned this Oct 16, 2018
@jrafanie jrafanie deleted the disable_transactional_tests_for_locking_tests_to_avoid_deadlock_on_5_1 branch December 14, 2018 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants