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

Release connections correctly #800

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions spec/avram/transaction_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ describe "Avram::SaveOperation" do
operation.saved?.should be_true
end
end

it "releases connection after operation finishes and no transactions open", tags: Avram::SpecHelper::TRUNCATE do
Copy link
Member Author

Choose a reason for hiding this comment

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

Have to truncate instead of wrap the specs in a transaction so that there will not be any open transactions left on the connection when the operation finishes.

PostTransactionSaveOperation.create!(title: "New Title", rollback_after_save: false)
TestDatabase.connections.should be_empty
end
end

describe "raising an error" do
Expand Down
3 changes: 1 addition & 2 deletions src/avram/database.cr
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ abstract class Avram::Database
rescue e : Avram::Rollback
false
ensure
# TODO: not sure of this
if current_connection._avram_in_transaction?
if !current_connection._avram_in_transaction?
current_connection.release
connections.delete(object_id)
end
Expand Down