Ownership process error while running phoenix test in elixir 1.3.2

I am working on a phoenix tutorial, but I have this error:

** (DBConnection.OwnershipError) cannot find ownership process for #PID<0.265.0>. 

I do not use Task.start , so nothing should be started asynchronously, and I thought that in order to prevent this error, in test/support/channel_case.ex :

it would be sufficient to use unless tag unless
  setup tags do :ok = Ecto.Adapters.SQL.Sandbox.checkout(Watchlist.Repo) unless tags[:async] do Ecto.Adapters.SQL.Sandbox.mode(Watchlist.Repo, {:shared, self()}) end :ok end 

So, I am curious how I resolve this error.

This is how I run it:

mix test test/integration/listing_movies_test.exs

I am using elixir 1.3.2

UPDATE

 defmodule ListingMoviesIntegrationTest do use ExUnit.Case, async: true use Plug.Test alias Watchlist.Router @opts Router.init([]) test 'listing movies' do movie = %Movie{name: "Back to the future", rating: 5} |> Repo.insert! <== error happens here conn = conn(:get, "/movies") response = Router.call(conn, @opts) assert response.status == 200 assert response.resp_body == movie end 

Full stack trace:

 (db_connection) lib/db_connection.ex:718: DBConnection.checkout/2 (db_connection) lib/db_connection.ex:619: DBConnection.run/3 (db_connection) lib/db_connection.ex:463: DBConnection.prepare_execute/4 (ecto) lib/ecto/adapters/postgres/connection.ex:91: Ecto.Adapters.Postgres.Connection.execute/4 (ecto) lib/ecto/adapters/sql.ex:235: Ecto.Adapters.SQL.sql_call/6 (ecto) lib/ecto/adapters/sql.ex:454: Ecto.Adapters.SQL.struct/6 (ecto) lib/ecto/repo/schema.ex:397: Ecto.Repo.Schema.apply/4 (ecto) lib/ecto/repo/schema.ex:193: anonymous fn/11 in Ecto.Repo.Schema.do_insert/4 (ecto) lib/ecto/repo/schema.ex:124: Ecto.Repo.Schema.insert!/4 test/integration/listing_movies_test.exs:13: (test) 

and in test_helper, which is actually called when I insert the debug statement:

 ExUnit.start Ecto.Adapters.SQL.Sandbox.mode(Watchlist.Repo, :manual) Ecto.Adapters.SQL.Sandbox.mode(Watchlist.Repo, {:shared, self()}) 
+7
source share
3 answers
 use ExUnit.Case, async: true use Plug.Test 

You have the code to install in "test / support / channel_case.ex", but you are not using it anywhere in your test, or at least it is not clear if you are using it. It would be helpful if you could add this:

 IO.puts "#{inspect __MODULE__}: setup is getting called." 

somewhere in your hook code. This will ensure that the code really works. My suspicion from the comment you made in my previous answer, this code is dead.

 defmodule ListingMoviesIntegrationTest do use ExUnit.Case, async: true use Plug.Test alias Watchlist.Router setup do :ok = Ecto.Adapters.SQL.Sandbox.checkout(Watchlist.Repo) Ecto.Adapters.SQL.Sandbox.mode(Watchlist.Repo, {:shared, self()}) :ok end @opts Router.init([]) test 'listing movies' do movie = %Movie{name: "Back to the future", rating: 5} |> Repo.insert! <== error happens here conn = conn(:get, "/movies") response = Router.call(conn, @opts) assert response.status == 200 assert response.resp_body == movie end ... 
+5
source

I think you skip this line

 Ecto.Adapters.SQL.Sandbox.mode(Watchlist.Repo, {:shared, self()}) 

because

 iex(1)> unless true do ...(1)> IO.puts "test" ...(1)> end nil iex(2)> unless false do ...(2)> IO.puts "test" ...(2)> end test :ok 

Have you tried:

 if tags[:async] do Ecto.Adapters.SQL.Sandbox.mode(Watchlist.Repo, {:shared, self()}) end 
0
source

I got the same error, and in my case on Elixir 1.8.2, Phoenix 1.4.1: after viewing this thread of the Elixir forum, I changed my test_helpers.exs so that in the line below test_helpers.exs the adapter pool mode is changed from manual to automatic.

 Ecto.Adapters.SQL.Sandbox.mode(MyApp.Repo, :auto) 

You can read more about this, about modes and about the pool, as well as about ownership on Hex Ecto docs.

0
source

All Articles