Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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

ishikawa@github
Developer in Tokyo ❤️Elixir
https://metareal.blog/
abeja
「ディープラーニング」を活用し、多様な業界、シーンにおけるビジネスの効率化・自動化を促進するベンチャー企業です。
https://abejainc.com
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