Skip to content

Commit

Permalink
ConversionController : répare test instable (#3460)
Browse files Browse the repository at this point in the history
* ConversionController : répare test instable

* Apply suggestions from code review

Co-authored-by: Thibaut Barrère <[email protected]>

---------

Co-authored-by: Thibaut Barrère <[email protected]>
  • Loading branch information
AntoineAugusti and thbar authored Sep 15, 2023
1 parent d2d6847 commit d8dd977
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ defmodule TransportWeb.ConversionControllerTest do

setup do
setup_telemetry_handler()
Ecto.Adapters.SQL.Sandbox.checkout(DB.Repo)
# See https://elixirforum.com/t/dbconnection-ownershiperror-cannot-find-ownership-process-for-pid-0-xxx-0/41373/3
# and https://github.com/etalab/transport-site/issues/3434
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(DB.Repo)
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
end

describe "get" do
Expand Down Expand Up @@ -63,8 +66,9 @@ defmodule TransportWeb.ConversionControllerTest do
assert_received {:telemetry_event, [:conversions, :get, :GeoJSON], %{}, %{target: ^target}}

# Need to wait a few milliseconds because the real telemetry handler
# writes rows in the database asynchronously
Process.sleep(50)
# writes rows in the database asynchronously.
# NOTE: to be improved in the future
Process.sleep(100)

assert [%DB.Metrics{target: ^target, event: "conversions:get:GeoJSON", period: ^period, count: 1}] =
DB.Metrics |> DB.Repo.all()
Expand Down

0 comments on commit d8dd977

Please sign in to comment.