zacksiri

zacksiri

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
async.

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: Ecto.Repo.Queryable.one/3
    (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} =
      start_supervised(
        {GRPC.Server.Supervisor, endpoint: InsterraGRPC.Endpoint, port: port, start_server: true},
        []
      )

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

  {:ok, conn: conn}
end

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
Hello ! We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement