Repository navigation
Sandbox: Allow {:late, id_tuple} - #762
mnussbaumer wants to merge 1 commit into
Conversation
…ip pool - the db_connection library needs to then be able to figure out when a :late binding is set
|
If we are going ahead with this, we definitely need more documentation, but another way to deal with this is for the message to set its $callers or $ancestors to something ownership can resolve. I wonder if |
I would be fine with writing more detailed documentation including a section specific for it and possibly tests. The issue with ancestors is that you still need to set them and my usual case the start is under a dynamic supervisor. There's probably ways to weave that into the started processes, but it seems like it might be much more convoluted? Anyway, I personally always felt like there should be a way to address these situations with allowances (and to an extent in Mox expectations too...) in the sense that: I know the name of the process, I know it's going to do something, I explicitly want to give it an allowance ahead of time but I can't because PIDs only exist after a process is started. I'm not too happy with the split between this and db_connection but I also don't see a way it could happen otherwise since the sandbox send the calls directly to the db_connection manager, not touching the paths here anymore. |
|
I believe Mox added support for anonymous functions, instead of |
|
This would mean that the To use a function it would mean introducing nimble_ownership for this case in the db_connection manager - I think this requires nimbleownership to be started and then for it to manage the pid allowances itself. So perhaps it would make more sense if it was to gradually migrate the sandbox model to use nimbleownership? Or you mean to change What I like in my proposal is that it's still just using native ways of addressing processes, meaning I'm open to exploring other options but I have not used nimbleownership so not entirely sure what would need to happen to implement it here, in defence of the |
|
No the plan is not to use nimble ownership, just to mirror its API for consistency. But there may be differences between them indeed, such as where it is resolved. |
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. In part this needs to touch also db_connection internals because part of the logic for the sandbox is there, due to the way it's architected.
Late allowances are useful for tests that you want asynchronous but for which you can't know the pid at test start, or processes that use the database on their own initial setup (init etc). For solving this you need to either use other sandbox mode and not use async tests or fiddle with your process code to allow special calls and cases during init depending on environment, either way, it always pushes the tests further from testing the real implementation of what's going to run in production.
The changes are minimal and they require specific formats so they should conflict with anything else. There would be ways of making this more readable by using the state of the processes currently being used for manager in db_connection, but that would be a bigger change. The API for a late binding allowance becomes:
For instance. There's a penalty paid when retrieving the real PID but this path only runs when the sandbox is in :manual, and there was no match. That path already raises today, so the cost, given it's probably only used for test contexts is near 0.
The db_connection PR is elixir-ecto/db_connection#364 (comment)
In total it's 10 lines here and 32 in db_connection.