LoginSignup
0

More than 3 years have passed since last update.

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

Posted at

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 のように書いた方がいいかもしれない。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0