Repository navigation
Allow late bindings for Ecto Sandbox - #364
Open
mnussbaumer wants to merge 1 commit into
Open
mnussbaumer wants to merge 1 commit into
mnussbaumer wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Ecto lacks a way of setting allowances for testing with late bindings, or in other words, allowing an "addressable" process name be used instead of the definitive pid the process is going to have.
With this change an API such as:
becomes possible, and this is useful to test processes that are dynamic and/or load data from the DB on their inits, without having to change the code or special case it for testing, nor using less strict sandbox/checkout modes, and still allowing asynchronous testing.
There needs to be a change to ecto_sql as well, and that's the PR elixir-ecto/ecto_sql#762 (comment)
This is already a slow path probably only touched upon during testing, there would be other ways of architecting this change but without wanting to change the current state format this seemed to be the ideal. Since you have to explicitly bind in this form there doesn't seem to be any penalty for those who don't use this form, but it could be also improved, by having a "allow_late_allowances"/"_bindings" option, that would only look for
{:late, ...}tuples if that option was turned on. I've tested this with my own code and it works, I am able to run several tests that before had to be written in varying ways, using the same type of allowance as for normal manual checkouts.