mailman-elixir / mailman

Mailman provides a clean way of defining mailers in your Elixir applications
https://github.com/mailman-elixir/mailman
Other
203 stars 73 forks source link

Ecto 2 Allowances for TestingAdapter #39

Closed nathany closed 8 years ago

nathany commented 8 years ago

When upgraded a Phoenix project to Ecto 2.0-beta.2 we see the following error in our mailer tests:

\ (RuntimeError) cannot find ownership process

There are two solutions to this issue, as documented in Ecto.Adapters.SQL.Sandbox.

For now we're using Shared mode, which works but runs the mailer tests synchronously. To have all the tests run concurrently, we could use Allowances in TestingAdapter:

defmodule Mailman.TestingAdapter do
  @moduledoc "Implementation of the testing SMTP adapter"

  def deliver(config, _email, message) do
    parent = self() # PID of the parent process
    Task.async fn ->
      Ecto.Adapters.SQL.Sandbox.allow(TestRepo, parent, self()) # need MyApp.Repo
      if config.store_deliveries do
        Mailman.TestServer.register_delivery message
      end
      { :ok, message }
    end
  end

end

We've tested this out, but with the name of our Repo hard coded. Do you think it would be possible to get this working?

keichan34 commented 8 years ago

Similar situation -- I'm working on making more of my tests async and Ecto 2.0. I'm currently using solutions in my PRs #44 and #45:

nathany commented 8 years ago

Thanks.

I agree it makes sense to not depend on Ecto. Does using independent test processes have any significant impact on how quickly tests run?

keichan34 commented 8 years ago

In my case, it's speeding tests up because the central TestServer was the bottleneck when doing a bunch of mailer tests in parallel.

nathany commented 8 years ago

Very nice. Thanks a bunch.

I'm gonna close this issue since you're obviously on top of it.