Skip to content

Allow late bindings for Ecto Sandbox - #364

Open
mnussbaumer wants to merge 1 commit into
elixir-ecto:masterfrom
mnussbaumer:late_allowances
Open

mnussbaumer wants to merge 1 commit into
elixir-ecto:masterfrom
mnussbaumer:late_allowances

Conversation

@mnussbaumer

Copy link
Copy Markdown

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:

Ecto.Adapters.SQL.Sandbox.allow(
      DB.Repo,
      self(),
      {:late, Statems.User.statem_global_id(player.id)}
)

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.

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