Skip to content

onboard transaction.exs suite, various transaction fixes#112

Merged
warmwaffles merged 2 commits intomainfrom
kcl-transaction-2
Mar 17, 2021
Merged

onboard transaction.exs suite, various transaction fixes#112
warmwaffles merged 2 commits intomainfrom
kcl-transaction-2

Conversation

@kevinlang
Copy link
Copy Markdown
Member

@kevinlang kevinlang commented Mar 17, 2021

The main test that was failing was this one, which was subsequently blocking the other tests was:

    @tag :transaction_checkout_raises
    test "checkout raises on transaction attempt" do
      assert_raise DBConnection.ConnectionError, ~r"connection was checked out with status", fn ->
        PoolRepo.checkout(fn -> PoolRepo.query!("BEGIN") end)
      end
    end

We assume that all transaction-beginning statements go through our handle_transaction call which is not the case. Here we don't detect we begin a transaction and thus don't know we are in an active transaction at "checkin" time, hence why the error is not thrown.

The fix is to add a new transaction_status NIF call that uses http://www.sqlite.org/c3ref/get_autocommit.html to return the current transaction status, and wiring that up in the correct places.

The second issue was that :disconnect was not properly rolling back a transaction. This is because sqlite3_close_v2 is not guaranteed to succeed, and indeed was going into a "zombie" state, as described at https://www.sqlite.org/c3ref/close.html . The fix for this was to make sure we atleast roll back any active transaction before doing this close logic, and then relying on the GC to clean the open prepared statements.

This closes #93 and likely also closes #58 .

…y rollingback when closing connection, onboard transaction.exs tests
@kevinlang kevinlang requested a review from warmwaffles March 17, 2021 02:43
Copy link
Copy Markdown
Member

@warmwaffles warmwaffles left a comment

Choose a reason for hiding this comment

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

Interesting find. Thank you for leaving that note there.

@warmwaffles warmwaffles merged commit 08a0a36 into main Mar 17, 2021
@warmwaffles warmwaffles deleted the kcl-transaction-2 branch March 17, 2021 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Onboard transaction.exs test suite Sandbox does not recover properly from errors, leading to busy issues

2 participants