Ecto test multiple process transaction in sandbox with shared connection

Ecto solves it by avoiding asynchronous preloading when a connection is checked out (inside test or transaction)

    Repo.transaction(fn ->
      task =
        if Repo.checked_out?() do
          Task.completed(%Post{title: "async"})
        else
          Task.async(fn ->
            %Post{title: "async"}
          end)
        end

      assert %Post{} = Repo.insert!(%Post{title: "sync"})
      assert %Post{} = Task.await(task)
    end)

Thanks to arnodirlam