Async tests with Ecto Sandbox and GRPC

I’m having trouble enabling async: true in my tests that involved GRPC endpoints.

I get the following error:

10:46:17.210 [error] ** (DBConnection.OwnershipError) cannot find ownership process for #PID<0.6663.0>.

When using ownership, you must manage connections in one
of the four ways:

* By explicitly checking out a connection
* By explicitly allowing a spawned process
* By running the pool in shared mode
* By using :caller option with allowed process

The first two options require every new process to explicitly
check a connection out or be allowed by calling checkout or
allow respectively.

The third option requires a {:shared, pid} mode to be set.
If using shared mode in tests, make sure your tests are not

The fourth option requires [caller: pid] to be used when
checking out a connection from the pool. The caller process
should already be allowed on a connection.

If you are reading this error, it means you have not done one
of the steps above or that the owner process has crashed.

See Ecto.Adapters.SQL.Sandbox docs for more information.
    (ecto_sql 3.10.2) lib/ecto/adapters/sql.ex:1044: Ecto.Adapters.SQL.raise_sql_call_error/1
    (ecto_sql 3.10.2) lib/ecto/adapters/sql.ex:945: Ecto.Adapters.SQL.execute/6
    (ecto 3.10.3) lib/ecto/repo/queryable.ex:229: Ecto.Repo.Queryable.execute/4
    (ecto 3.10.3) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/3
    (ecto 3.10.3) lib/ecto/repo/queryable.ex:151:
    (insterra 0.1.0) lib/insterra_grpc/servers/blueprint_server.ex:369: InsterraGRPC.BlueprintServer.update_component/2
    (grpc 0.7.0) lib/grpc/server.ex:187: anonymous fn/6 in GRPC.Server.call_with_interceptors/4
    (grpc 0.7.0) lib/grpc/telemetry.ex:94: anonymous fn/2 in GRPC.Telemetry.server_span/5
    (telemetry 1.2.1) /Users/zacksiri/Development/_upmaru/insterra/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
    (grpc 0.7.0) lib/grpc/telemetry.ex:93: GRPC.Telemetry.server_span/5
    (grpc 0.7.0) lib/grpc/server/adapters/cowboy/handler.ex:376: GRPC.Server.Adapters.Cowboy.Handler.do_call_rpc/3
    (grpc 0.7.0) lib/grpc/server/adapters/cowboy/handler.ex:349: GRPC.Server.Adapters.Cowboy.Handler.call_rpc/3

The app is just a phoenix app, and I have my own custom GRPC endpoint in the application.ex

If I just use Insterra.DataCase without async: true tests run without any issues. I’ve looked online to find examples of how people test their GRPC endpoint and couldn’t find any.

Here is how i setup my GPRC conn for tests

setup do
  port = Enum.random(20000..20999)

  {:ok, _server_pid} =
        {GRPC.Server.Supervisor, endpoint: InsterraGRPC.Endpoint, port: port, start_server: true},

  {:ok, conn} = GRPC.Stub.connect("localhost:#{port}")

  {:ok, conn: conn}