0
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

Organization

Ecto 3.17 から 3.2.2 にアップデート: Migration のテスト

Ecto 3.17 から 3.2.2 にアップデート: use Ecto.Type からのつづき。

Ecto.Migration に用意された関数だけでなく、いくつか独自の Migration ロジックがあるので、Ecto.Migration.Supervisor を使ってテストを書いていたがこれが動かなくなっていた。

     ** (exit) exited in: GenServer.call(Ecto.Migration.Supervisor, {:start_child, [#PID<0.1016.0>, MyApp.MasterRepo, MyApp.Migration.ResourceTest.MigrationModule, :forward, :up, %{level: :warn, sql: false}]}, :infinity)
         ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started

そのため、ecto_sql のテストを参考に、以下のように書き換えたところ動作した。

   setup do
     level = Application.get_env(:logger, :level, :info)
     log = %{level: level, sql: false}
-    args = [self(), MasterRepo, MigrationModule, :forward, :up, log]

-    {:ok, runner} = Supervisor.start_child(Ecto.Migration.Supervisor, args)
-    Ecto.Migration.Runner.metadata(runner, prefix: "test.migration.resource")
+    {:ok, runner} =
+      Ecto.Migration.Runner.start_link({self(), MasterRepo, MigrationModule, :forward, :up, log})

+    Ecto.Migration.Runner.metadata(runner, prefix: "test.migration.resource")
     {:ok, %{runner: runner}}
   end

もっとも、Ecto の実装が変わるたびに書き換えが必要になるのはメンテナンス性が悪い(書き換えるのも二度目)。ecto_sql の integration test のように書いた方がいいかもしれない。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
0
Help us understand the problem. What are the problem?