Skip to content

Fix a problem where tests were leaving leftover jobs in the database - #28

Merged
brandur merged 1 commit into
masterfrom
brandur-test-transaction-fix
Jul 6, 2024
Merged

Fix a problem where tests were leaving leftover jobs in the database#28
brandur merged 1 commit into
masterfrom
brandur-test-transaction-fix

Conversation

@brandur

@brandur brandur commented Jul 6, 2024

Copy link
Copy Markdown
Contributor

Fix a problem where tests were leaving leftover jobs in the database
which turns out to be because SQLAlchemy stupidly doesn't start a
transaction when begin() is called, which was having the effect of the
unique job check starting a top-level transaction instead of savepoint,
thereby committing insert results outside of the test transactions.

This took an insanely long time to track down, and I ended up adding a
number of extra measures to help find the problem which I'm also keeping
for the time begin:

  • RIVER_DEBUG activates debug logging for SQLAlchemy, showing queries
    and connection pool activity.

  • An autorunning fixture checks for extra jobs after each test case to
    make sure nothing gets leftover.

  • SimpleArgs starts to internalize the name of the test that created
    it, so upon seeing an extraneous row, it's easy to know exactly where
    it came from. It becomes a fixture to make this terse.

Fix a problem where tests were leaving leftover jobs in the database
which turns out to be because SQLAlchemy stupidly doesn't start a
transaction when `begin()` is called, which was having the effect of the
unique job check starting a top-level transaction instead of savepoint,
thereby committing insert results outside of the test transactions.

This took an insanely long time to track down, and I ended up adding a
number of extra measures to help find the problem which I'm also keeping
for the time begin:

* `RIVER_DEBUG` activates debug logging for SQLAlchemy, showing queries
  and connection pool activity.

* An autorunning fixture checks for extra jobs after each test case to
  make sure nothing gets leftover.

* `SimpleArgs` starts to internalize the name of the test that created
  it, so upon seeing an extraneous row, it's easy to know exactly where
  it came from. It becomes a fixture to make this terse.
@brandur
brandur merged commit 343e823 into master Jul 6, 2024
@brandur
brandur deleted the brandur-test-transaction-fix branch July 6, 2024 21:56
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.

1 participant