svilen

svilen

Author of Concurrent Data Processing in Elixir

Running async tests with Hound?

I’m using Hound with ChromeDriver and I’ve read that it is possible to run async tests (e.g. multiple browsers executing the test cases in parallel). However, I can’t find any examples/tutorials how to do this.

There’s a question on StackOverflow that was kind of a starting point, but I was still getting DBConnection.OwnershipError exceptions or other timeout errors. Then I saw this answer in the forum saying that Wallaby/Hound support async tests through a plug found in Ecto.

Could someone provide a short example how to get this working? Thanks a lot in advance!

Elixir 1.4 / Phoenix 1.3rc

Most Liked

svilen

svilen

Author of Concurrent Data Processing in Elixir

@josevalim Thanks for the quick response, that was very helpful! I’m surprised Hound’s README doesn’t have a link to it. However, I’m still struggling to get this to work the way I think it should be.

I’ve got two tests, and when ran individually, they take ~15 seconds each (or ~30 seconds with mix test --only integration). After I added async: true I can see two Chrome browsers starting off, but strangely the total time with the async options and changes is still ~30 seconds, same as before, which seems wrong.

How could this be, is there something I’m missing? I followed the guide in the link carefully, and only made 1 change in the setup of my IntegrationCase file, due to an error:

defmodule MyApp.Web.IntegrationCase do
  use ExUnit.CaseTemplate

  using do
    quote do
      use Hound.Helpers
      import MyApp.Web.Router.Helpers
      import MyApp.Web.IntegrationCase

      @endpoint MyApp.Web.Endpoint

      hound_session()
    end
  end

  setup do
    :ok = Ecto.Adapters.SQL.Sandbox.checkout(MyApp.Repo)
    metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for(MyApp.Repo, self())
    Hound.start_session(metadata: metadata)
    # Added :ok since `start_session/2` returns a string.
    :ok
  end
end
josevalim

josevalim

Creator of Elixir

Tests in the same module do not run concurrently. Only tests in separate modules/files. I.e. the granularity of concurrency is per module and not per test. That’s because tests in the same module/file are usually exercising the same area of the codebase and would not benefit of concurrency.

Last Post!

myobie

myobie

I recently used Hound as part of a GenStage pipeline (and spawned about 15 of this particular stage to run concurrently) and this is the code that worked well for me. I think you could create a GenServer and do the same (spawn a process for each test so they are fully isolated).

Where Next?

Popular in Questions Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44608 311
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement