Skip to content

Commit

Permalink
Try to fix some flaky tests (#326)
Browse files Browse the repository at this point in the history
* Add handle_info fallback to BikeBrigadeWeb.CampaignSignupLive.Show

* Simplify delivery url and fix test

* Turn off async for live tests

* Use the start_owner/stop_owner for SQL sandbox

See phoenixframework/phoenix#3856

* Bump some dpes
  • Loading branch information
mveytsman authored Apr 17, 2024
1 parent e298dc6 commit f5fa414
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
15 changes: 1 addition & 14 deletions lib/bike_brigade/delivery.ex
Original file line number Diff line number Diff line change
Expand Up @@ -569,20 +569,7 @@ defmodule BikeBrigade.Delivery do
end
|> Enum.join("\n\n")

{destination, waypoints} = List.pop_at(locations, -1)

# TODO: this is the same as DeliveryHelpers.directions_url
map_query =
URI.encode_query(%{
api: 1,
travelmode: "bicycling",
origin: rider.location,
waypoints: Enum.join(waypoints, "|"),
destination: destination
})

directions = "https://www.google.com/maps/dir/?#{map_query}"

directions = BikeBrigade.GoogleMaps.directions_url(rider.location, locations)
delivery_details_url = url(~p"/app/delivery/#{rider.delivery_url_token}")

campaign_date = LocalizedDateTime.to_date(campaign.delivery_start)
Expand Down
4 changes: 4 additions & 0 deletions lib/bike_brigade_web/live/campaign_signup_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do
end
end

@impl Phoenix.LiveView
@doc "silently ignore other kinds of messages"
def handle_info(_, socket), do: {:noreply, socket}

## lil helpers

defp get_task(socket, id) when is_binary(id), do: get_task(socket, String.to_integer(id))
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule BikeBrigade.MixProject do
{:ex_phone_number, "~> 0.2"},
{:ecto_enum, "~> 1.4"},
{:geo_postgis, "~> 3.4.0"},
{:lib_lat_lon, "~> 0.7"},
{:lib_lat_lon, "~> 0.7.1"},
# required by lib_lat_lon
{:nextexif, "~> 0.0"},
{:topo, "~> 0.4.0"},
Expand Down
47 changes: 24 additions & 23 deletions mix.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion test/bike_brigade/delivery_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ defmodule BikeBrigade.DeliveryTest do
"""

directions_url =
"https://www.google.com/maps/dir/?api=1&destination=#{to_uri(task.dropoff_location)}&origin=#{to_uri(rider.location)}&travelmode=bicycling&waypoints=#{to_uri(campaign.location)}"
BikeBrigade.GoogleMaps.directions_url(rider.location, [
campaign.location,
task.dropoff_location
])

assert Delivery.render_campaign_message_for_rider(campaign, message, rider) ==
"""
Expand Down
2 changes: 1 addition & 1 deletion test/bike_brigade_web/live/campaign_signup_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule BikeBrigadeWeb.CampaignSignupLiveTest do
use BikeBrigadeWeb.ConnCase, only: []
use BikeBrigadeWeb.ConnCase, async: false
alias BikeBrigade.LocalizedDateTime

import Phoenix.LiveViewTest
Expand Down
2 changes: 1 addition & 1 deletion test/bike_brigade_web/live/rider_home_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule BikeBrigadeWeb.RiderHomeLiveTest do
use BikeBrigadeWeb.ConnCase, only: []
use BikeBrigadeWeb.ConnCase, async: false
alias BikeBrigade.LocalizedDateTime

import Phoenix.LiveViewTest
Expand Down
13 changes: 9 additions & 4 deletions test/support/conn_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ defmodule BikeBrigadeWeb.ConnCase do
end

setup tags do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(BikeBrigade.Repo)
repo_pid = Ecto.Adapters.SQL.Sandbox.start_owner!(BikeBrigade.Repo, shared: not tags[:async])

unless tags[:async] do
Ecto.Adapters.SQL.Sandbox.mode(BikeBrigade.Repo, {:shared, self()})
end
on_exit(fn ->
Ecto.Adapters.SQL.Sandbox.stop_owner(repo_pid)

# for pid <- BikeBrigade.Presence.fetchers_pids() do
# ref = Process.monitor(pid)
# assert_receive {:DOWN, ^ref, _, _, _}, 1000
# end
end)

{:ok, conn: Phoenix.ConnTest.build_conn()}
end
Expand Down

0 comments on commit f5fa414

Please sign in to comment.