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

Fix dramatiq test issue leading to stack overflow #649

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

rohanpm
Copy link
Member

@rohanpm rohanpm commented Dec 12, 2023

Dramatiq actors are declared at import time, before our test fixtures have had a chance to set up the test DB. In order to ensure dramatiq points at the test DB, the prior solution was an autouse fixture which would create a new temporary broker pointing at the test DB and move all existing actors over to that.

There was a major issue with this which went unnoticed: all the middlewares were recreated each time. Since some of the middlewares work by wrapping the functions on the actors, this meant every test would add a new level of wrapped functions on top of those already set up by prior tests. Once the total number of tests exceeds some threshold, the number of chained functions would be high enough to cause a stack overflow.

This commit changes the approach used to point the broker at our test DB. Rather than creating a new Broker (and new middlewares) per test, we keep the same one throughout and we add a method to it which allows resetting the DB engine and settings on the fly.

Dramatiq actors are declared at import time, before our test fixtures
have had a chance to set up the test DB. In order to ensure dramatiq
points at the test DB, the prior solution was an autouse fixture which
would create a new temporary broker pointing at the test DB and move
all existing actors over to that.

There was a major issue with this which went unnoticed: all the
middlewares were recreated each time. Since some of the middlewares work
by wrapping the functions on the actors, this meant every test would add
a new level of wrapped functions on top of those already set up by prior
tests. Once the total number of tests exceeds some threshold, the number
of chained functions would be high enough to cause a stack overflow.

This commit changes the approach used to point the broker at our test
DB. Rather than creating a new Broker (and new middlewares) per test, we
keep the same one throughout and we add a method to it which allows
resetting the DB engine and settings on the fly.
@rohanpm rohanpm marked this pull request as ready for review December 12, 2023 21:10
@rohanpm rohanpm merged commit 38f8262 into release-engineering:master Dec 13, 2023
3 checks passed
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.

None yet

2 participants