Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

1
0
0

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
  3. You can use dark theme
What you can do with signing up

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?