Repository: elixir-ecto/ecto

Issue #1259: Mix.Task.run "ecto.migrate" in test_helper?
Created: 2016-02-19T15:55:19Z
I might be way off here, but I'm having some issues with my test_helper.exs using Ecto 2.0 (master and beta)
I tried setting it up like this:
  alias Ecto2Test.Repo

  defmodule Ecto2Test.Integration.Case do
    use ExUnit.CaseTemplate

    setup do
      :ok = Ecto.Adapters.SQL.Sandbox.checkout(Ecto2Test.Repo)
    end
  end

  {:ok, _} = Ecto2Test.Repo.start_link

  _   = Ecto.Storage.down(Ecto2Test.Repo)
  _   = Ecto.Storage.up(Ecto2Test.Repo)

  Mix.Task.run "ecto.create", ["-r", Ecto2Test.Repo, "--quiet"]
  Mix.Task.run "ecto.migrate", ["-r", Ecto2Test.Repo, "--quiet"]

  Ecto.Adapters.SQL.Sandbox.mode(Ecto2Test.Repo, :manual)

  ExUnit.start()
but then it errors out with:
** (exit) exited in: GenServer.call(Ecto2Test.Repo.Pool, {:mode, :manual}, 5000)
    ** (EXIT) no process
    (elixir) lib/gen_server.ex:564: GenServer.call/3
    test/test_helper.exs:23: (file)
    (elixir) lib/code.ex:363: Code.require_file/2
    (elixir) lib/enum.ex:604: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:604: Enum.each/2


16:34:40.753 [error] GenServer #PID<0.178.0> terminating
** (stop) exited in: GenServer.call(Ecto2Test.Repo.Pool, {:mode, :manual}, 5000)
    ** (EXIT) no process
Last message: {:EXIT, #PID<0.47.0>, {:noproc, {GenServer, :call, [Ecto2Test.Repo.Pool, {:mode, :manual}, 5000]}}}
State: {:state, {#PID<0.178.0>, Supervisor.Default}, :simple_one_for_one, [{:child, :undefined, Task.Supervised, {Task.Supervised, :start_link, []},
 :temporary, 5000, :worker, [Task.Supervised]}], {:set, 0, 16, 16, 8, 80, 48, {[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []}, {{[]
, [], [], [], [], [], [], [], [], [], [], [], [], [], [], []}}}, 3, 5, [], Supervisor.Default, {:ok, {{:simple_one_for_one, 3, 5}, [{Task.Supervised
, {Task.Supervised, :start_link, []}, :temporary, 5000, :worker, [Task.Supervised]}]}}}

If I change my test_helper.exs to this:
  alias Ecto2Test.Repo

+ Code.require_file "../priv/repo/migrations/1_create_users.exs", __DIR__

  defmodule Ecto2Test.Integration.Case do
    use ExUnit.CaseTemplate

    setup do
      :ok = Ecto.Adapters.SQL.Sandbox.checkout(Ecto2Test.Repo)
    end
  end

  {:ok, _} = Ecto2Test.Repo.start_link

  _   = Ecto.Storage.down(Ecto2Test.Repo)
  _   = Ecto.Storage.up(Ecto2Test.Repo)

  Mix.Task.run "ecto.create", ["-r", Ecto2Test.Repo, "--quiet"]
- Mix.Task.run "ecto.migrate", ["-r", Ecto2Test.Repo, "--quiet"]

+ Ecto.Migrator.up(Ecto2Test.Repo, 1, Ecto2Test.Repo.Migrations.CreateUsers)

  Ecto.Adapters.SQL.Sandbox.mode(Ecto2Test.Repo, :manual)

  ExUnit.start()
It works fine.
I've put up an example project here: https://github.com/tmjoen/ecto2_test
Just wondering if there are some gremlins in the machine here, or if I'm not really supposed to do Mix.Task.run "ecto.migrate", ["-r", Ecto2Test.Repo, "--quiet"] like Phoenix can?

Duplicate issue #1263: Random issue when running mix test
Created: 2016-02-21T00:33:29Z
I have had that error a couple of times now when running mix test with the Ecto 2.0 beta.
I'm not sure where it's coming from but thought it would be useful to report it.
# run test once with incorrect test
$ mix test test/controllers/session_controller_test.exs
....

Finished in 0.4 seconds (0.2s on load, 0.2s on tests)
4 tests, 0 failures

Randomized with seed 243590

# change file to fix, test should now fail but instead I get this error
$ mix test test/controllers/session_controller_test.exs
** (exit) exited in: GenServer.call(Repo.Pool, {:mode, :manual}, 5000)
    ** (EXIT) no process
    (elixir) lib/gen_server.ex:564: GenServer.call/3
    (elixir) lib/code.ex:363: Code.require_file/2
    (elixir) lib/enum.ex:604: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:604: Enum.each/2
    (mix) lib/mix/tasks/test.ex:186: Mix.Tasks.Test.run/1

00:22:12.487 [error] GenServer #PID<0.375.0> terminating
** (stop) exited in: GenServer.call(Repo.Pool, {:mode, :manual}, 5000)
    ** (EXIT) no process

# run mix test again, working fine now (failing test is expected)
$ mix test test/controllers/session_controller_test.exs
..

  1) test POST /auth/callback/identity with incorrect details (SessionControllerTest)
     test/controllers/session_controller_test.exs:26
     ** (FunctionClauseError) no function clause matching in Kernel.=~/2
     stacktrace:
       (elixir) lib/kernel.ex:1500: Kernel.=~(nil, "Signed in as")
       test/controllers/session_controller_test.exs:33

.

Finished in 0.4 seconds (0.2s on load, 0.2s on tests)
4 tests, 1 failure
Let me know if you need more details.

Closing comment (2016-02-21T10:09:56Z): Related to #1259.