Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gracefully handle predictions v2 for empty stop list #232

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ defmodule MobileAppBackendWeb.PredictionsForStopsV2Channel do
)

if stop_id_concat == "" do
{:error, %{code: :no_stop_ids}}
{:ok,
%{
predictions_by_stop: %{},
trips: %{},
vehicles: %{}
}, socket}
else
{time_micros, initial_data} =
:timer.tc(fn ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ defmodule MobileAppBackendWeb.PredictionsForStopsV2ChannelTest do

response = %{
predictions_by_stop: %{
"12345" => %{"p_1" => prediction_1, "p_2" => prediction_2},
trips: %{"trip_1" => trip_1, "trip_2" => trip_2},
vehicles: %{"v_1" => vehicle_1, "v_2" => vehicle_2}
}
"12345" => %{"p_1" => prediction_1, "p_2" => prediction_2}
},
trips: %{"trip_1" => trip_1, "trip_2" => trip_2},
vehicles: %{"v_1" => vehicle_1, "v_2" => vehicle_2}
Comment on lines 34 to +38
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test data had the wrong shape, and that could be confusing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing!

}

expect(PredictionsPubSubMock, :subscribe_for_stops, 1, fn _ ->
Expand All @@ -48,9 +48,11 @@ defmodule MobileAppBackendWeb.PredictionsForStopsV2ChannelTest do
assert reply == response
end

test "error if missing stop ids in topic", %{socket: socket} do
{:error, %{code: :no_stop_ids}} =
subscribe_and_join(socket, "predictions:stops:v2:")
test "empty data if missing stop ids in topic", %{socket: socket} do
assert {:ok, data, _socket} =
subscribe_and_join(socket, "predictions:stops:v2:")

assert data == %{predictions_by_stop: %{}, trips: %{}, vehicles: %{}}
end

test "handles new predictions", %{socket: socket} do
Expand Down
Loading