Using same Ecto Sandbox Connection for two Repos

Hi there

I’m currently developing a Phoenix App that acts as a view for two sub applications. I.e. the layout in terms of umbrella projects is something like this:

- apps
    - appA
    - appB
    - appPhoenix

appA and appB each have their own Repo, but appB is based on appA and writes to the same database (there are foreign key constraints in appB based on appA). appA itself is used across multiple projects.

Now I’d like to write some tests in appPhoenix where I test the json API it is offering to see if e.g. a POST request does what it is supposed to. For the test I’m using the Ecto Sandbox in shared mode, which is working fine as long as the request I’m sending does not require both Repo’s from appA and appB. The problem is obviously that I did check out a :shared connection for appB.Repo in the test setup, i.e.:

  setup tags do
    :ok = Ecto.Adapters.SQL.Sandbox.checkout(appB.Repo)

    unless tags[:async] do
      Ecto.Adapters.SQL.Sandbox.mode(appB.Repo, {:shared, self()})


But obviously appA has it’s own repo and that one is not setup to use the same connection like appB.Repo.

My question now is: Is there a possibility to configure the appA.Repo to use the same shared connection that appB.Repo is using in the tests? So far I’ve not been able to setup such a configurtation, any help would be much appreciated.


Like this?

Hmm, that could work. I’ll give it a try