Skip to content

Commit

Permalink
Restart state app before each test.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaddox5 committed Dec 17, 2024
1 parent 0ac192f commit fa0d08a
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ defmodule ApiWeb.AlertControllerTest do

setup tags do
State.Stop.new_state([%Model.Stop{}])
State.Trip.new_state([])
State.Route.new_state([])
State.Schedule.new_state([])
State.RoutesPatternsAtStop.update!()

Facility.new_state([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ defmodule ApiWeb.HealthControllerTest do
end

test "defaults to 503", %{conn: conn} do
State.Alert.new_state([])
State.Schedule.new_state([])
State.StopsOnRoute.update!()
conn = get(conn, health_path(conn, :index))
assert json_response(conn, 503)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,11 @@ defmodule ApiWeb.PredictionController.SortByArrivalTimeTest do
}
]

setup_all do
setup %{conn: conn} do
# stop is needed since we look up parent stops
State.Stop.new_state([@stop, @parent_stop])
State.Trip.new_state([])
State.Route.new_state([@route1, @route2, @route3])
State.Prediction.new_state(Enum.shuffle(@cr_predictions))
:ok
end

setup %{conn: conn} do
{:ok, conn: put_req_header(conn, "accept", "application/json")}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ defmodule ApiWeb.PredictionControllerTest do
@cr_prediction hd(@cr_predictions)

setup %{conn: conn} do
State.Trip.new_state([])
# stop is needed since we look up parent stops
State.Stop.new_state([@stop, @parent_stop, %Stop{id: "2"}])
State.Prediction.new_state(@cr_predictions)
Expand Down Expand Up @@ -584,7 +583,6 @@ defmodule ApiWeb.PredictionControllerTest do

test "does not return alerts when no alerts exist", %{conn: conn} do
different_route_prediction = %{@cr_prediction | route_id: "red", trip_id: "trip2"}
State.Alert.new_state([])
State.Prediction.new_state([different_route_prediction, @cr_prediction])

include_nothing_conn =
Expand Down Expand Up @@ -626,7 +624,6 @@ defmodule ApiWeb.PredictionControllerTest do
%{conn: conn} do
# run it 100 times since it's a race condition between State.Prediction and State.Trip.Added
for _ <- 0..100 do
State.Prediction.new_state([])
# wait for State,Trip.Added to clear
State.Trip.Added.last_updated()
# need a stop ID to generate an Added trip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule ApiWeb.StopControllerTest do
alias Model.{Facility, Schedule, Stop, Trip}

setup %{conn: conn} do
State.Stop.new_state([])
{:ok, conn: put_req_header(conn, "accept", "application/json")}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ defmodule ApiWeb.TripControllerTest do
alias Model.Trip

setup %{conn: conn} do
State.Trip.new_state([])

{:ok, conn: put_req_header(conn, "accept", "application/json")}
end

Expand Down
1 change: 0 additions & 1 deletion apps/api_web/test/api_web/event_stream_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ defmodule ApiWeb.EventStreamTest do

setup %{conn: conn} do
CheckForShutdown.reset()
State.Prediction.new_state([])

conn =
conn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule ApiWeb.Plugs.ExperimentalFeaturesTest do
import Phoenix.ConnTest
use ApiWeb.ConnCase, async: true
use ApiWeb.ConnCase

test "init" do
assert ApiWeb.Plugs.ExperimentalFeatures.init([]) == []
Expand Down
3 changes: 1 addition & 2 deletions apps/api_web/test/api_web/views/api_view_helpers_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule ApiWeb.ApiViewHelpersTest do
use ExUnit.Case
use ApiWeb.ConnCase
alias ApiWeb.ApiViewHelpers
import ApiViewHelpers

Expand Down Expand Up @@ -35,7 +35,6 @@ defmodule ApiWeb.ApiViewHelpersTest do
end

test "otherwise uses trip_id to lookup trip" do
State.Trip.new_state([])
conn = %Plug.Conn{assigns: %{split_include: MapSet.new(["trip"])}}

assert trip(%{trip_id: @trip_id}, conn) == nil
Expand Down
5 changes: 0 additions & 5 deletions apps/api_web/test/api_web/views/facility_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ defmodule ApiWeb.FacilityViewTest do
longitude: -71.794593
}

setup do
State.Facility.Property.new_state([])
:ok
end

test "can do a basic rendering", %{conn: conn} do
rendered = render("index.json-api", data: @facility, conn: conn)["data"]
assert rendered["type"] == "facility"
Expand Down
5 changes: 5 additions & 0 deletions apps/api_web/test/support/conn_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ defmodule ApiWeb.ConnCase do

setup _tags do
conn = conn_with_api_key(Phoenix.ConnTest.build_conn())

# Ensure each test is using a fresh instance of State modules
Application.stop(:state)
Application.start(:state)

{:ok, conn: conn}
end

Expand Down
6 changes: 2 additions & 4 deletions apps/state/test/state/trip/added_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ defmodule State.Trip.AddedTest do
{:ok, %{shape: shape, prediction: prediction}}
end

test "if there's a matching shape for the route/direction, uses the last stop from that shape",
%{prediction: prediction} do
test "if there's a matching shape for the route/direction, uses the last stop from that shape" do
predictions = [
%{@prediction | stop_sequence: 3, stop_id: "child"},
%{@prediction | stop_sequence: 2, stop_id: "other"}
Expand All @@ -190,8 +189,7 @@ defmodule State.Trip.AddedTest do
assert [%{headsign: "Last Stop on Shape"}] = by_id(@trip_id)
end

test "if there's a matching shape for the route/direction and it's a subway route, uses the last predicted stop",
%{prediction: prediction} do
test "if there's a matching shape for the route/direction and it's a subway route, uses the last predicted stop" do
State.Route.new_state([%Model.Route{id: @route_id, type: 0}])

predictions = [
Expand Down

0 comments on commit fa0d08a

Please sign in to comment.