Fix dramatiq test issue leading to stack overflow #649
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.