From 7ef9e248a04ca461a75024db57c4c17ffbadb3fa Mon Sep 17 00:00:00 2001 From: Cora Grant Date: Thu, 18 Jul 2024 15:29:00 -0400 Subject: [PATCH] feat: signs can have a "default mode" Previously, if a sign wasn't configured in SignsUI, it would always be in the `off` mode. We'd like to be able to configure our new lab signs for testing without the complexity of supporting this unique "kind" of sign in SignsUI as well as this project. This adds an optional `default_mode` field to sign configuration, which can be set to any of the "modes" supported by SignsUI. For now, this is only supported by `Realtime` (a.k.a. subway) signs and not `Bus` signs, but this would be easy enough to extend later if needed. Due to now needing a sign's default mode as well as its ID whenever we want to determine its "current mode", this includes a refactor of the previously-added `current_config` logging so the value is determined when a message is enqueued, instead of when it is later processed. --- lib/engine/config.ex | 10 +++---- lib/engine/config_api.ex | 3 ++- lib/message_queue.ex | 11 ++++---- lib/pa_ess/http_updater.ex | 45 ++++++++++++------------------- lib/pa_ess/updater.ex | 26 +++++++++++++----- lib/signs/bus.ex | 6 +++-- lib/signs/realtime.ex | 6 ++++- priv/signs.json | 1 + test/engine/config_test.exs | 22 +++++++-------- test/message_queue_test.exs | 8 +++--- test/pa_ess/http_updater_test.exs | 22 +++++++-------- test/signs/bus_test.exs | 8 +++--- test/signs/realtime_test.exs | 33 ++++++++++++++++------- 13 files changed, 112 insertions(+), 89 deletions(-) diff --git a/lib/engine/config.ex b/lib/engine/config.ex index d8f68770e..606c0c297 100644 --- a/lib/engine/config.ex +++ b/lib/engine/config.ex @@ -32,10 +32,10 @@ defmodule Engine.Config do end @impl true - def sign_config(table_name \\ @table_signs, sign_id) do - case :ets.lookup(table_name, sign_id) do - [{^sign_id, config}] -> config - _ -> :off + def sign_config(table \\ @table_signs, sign_id, default) do + case :ets.lookup(table, sign_id) do + [{^sign_id, config}] when not is_nil(config) -> config + _ -> default end end @@ -200,7 +200,7 @@ defmodule Engine.Config do :temporary_terminal true -> - :off + nil end end diff --git a/lib/engine/config_api.ex b/lib/engine/config_api.ex index 4915251ab..452afb1ad 100644 --- a/lib/engine/config_api.ex +++ b/lib/engine/config_api.ex @@ -1,5 +1,6 @@ defmodule Engine.ConfigAPI do - @callback sign_config(String.t()) :: Engine.Config.sign_config() + @callback sign_config(id :: String.t(), default :: Engine.Config.sign_config()) :: + Engine.Config.sign_config() @callback headway_config(String.t(), DateTime.t()) :: Engine.Config.Headway.t() | nil @callback scu_migrated?(String.t()) :: boolean() end diff --git a/lib/message_queue.ex b/lib/message_queue.ex index ef551492e..59435248a 100644 --- a/lib/message_queue.ex +++ b/lib/message_queue.ex @@ -39,12 +39,12 @@ defmodule MessageQueue do Content.Message.value(), integer(), integer() | :now, - String.t() + keyword() ) :: :ok - def update_sign(pid \\ __MODULE__, text_id, top_line, bottom_line, duration, start, sign_id) do + def update_sign(pid \\ __MODULE__, text_id, top_line, bottom_line, duration, start, log_meta) do GenServer.call( pid, - {:queue_update, {:update_sign, [text_id, top_line, bottom_line, duration, start, sign_id]}} + {:queue_update, {:update_sign, [text_id, top_line, bottom_line, duration, start, log_meta]}} ) end @@ -54,13 +54,12 @@ defmodule MessageQueue do [Content.Audio.value()], integer(), integer(), - String.t(), [keyword()] ) :: :ok - def send_audio(pid \\ __MODULE__, audio_id, audios, priority, timeout, sign_id, extra_logs) do + def send_audio(pid \\ __MODULE__, audio_id, audios, priority, timeout, log_metas) do GenServer.call( pid, - {:queue_update, {:send_audio, [audio_id, audios, priority, timeout, sign_id, extra_logs]}} + {:queue_update, {:send_audio, [audio_id, audios, priority, timeout, log_metas]}} ) end diff --git a/lib/pa_ess/http_updater.ex b/lib/pa_ess/http_updater.ex index 96072eb8d..0e2a8d84a 100644 --- a/lib/pa_ess/http_updater.ex +++ b/lib/pa_ess/http_updater.ex @@ -60,7 +60,7 @@ defmodule PaEss.HttpUpdater do end def process( - {:update_sign, [{station, zone}, top_line, bottom_line, duration, start_secs, sign_id]}, + {:update_sign, [{station, zone}, top_line, bottom_line, duration, start_secs, log_meta]}, state ) do top_cmd = to_command(top_line, duration, start_secs, zone, 1) @@ -78,29 +78,23 @@ defmodule PaEss.HttpUpdater do {arinc_ms, signs_ui_ms, result} = send_payload(encoded, state) - log("update_sign", encoded, - arinc_ms: arinc_ms, - signs_ui_ms: signs_ui_ms, - top_line: inspect(top_line), - bottom_line: inspect(bottom_line), - sign_id: sign_id, - current_config: - case Engine.Config.sign_config(sign_id) do - type when is_atom(type) -> type - tuple when is_tuple(tuple) -> elem(tuple, 0) - _ -> nil - end + log( + "update_sign", + encoded, + [ + arinc_ms: arinc_ms, + signs_ui_ms: signs_ui_ms, + top_line: inspect(top_line), + bottom_line: inspect(bottom_line) + ] ++ log_meta ) result end - def process( - {:send_audio, [{station, zones}, audios, priority, timeout, sign_id, extra_logs]}, - state - ) do - for {audio, extra_logs} <- Enum.zip(audios, extra_logs) do - process_send_audio(station, zones, audio, priority, timeout, sign_id, extra_logs, state) + def process({:send_audio, [{station, zones}, audios, priority, timeout, log_metas]}, state) do + for {audio, log_meta} <- Enum.zip(audios, log_metas) do + process_send_audio(station, zones, audio, priority, timeout, log_meta, state) end |> List.last() end @@ -111,12 +105,11 @@ defmodule PaEss.HttpUpdater do Content.Audio.value(), integer(), integer(), - String.t(), - list, + keyword(), t() ) :: post_result() - defp process_send_audio(station, zones, audio, priority, timeout, sign_id, extra_logs, state) do + defp process_send_audio(station, zones, audio, priority, timeout, log_meta, state) do case audio do {:canned, {message_id, vars, type}} -> encoded = @@ -134,11 +127,7 @@ defmodule PaEss.HttpUpdater do {arinc_ms, signs_ui_ms, result} = send_payload(encoded, state) - log( - "send_audio", - encoded, - [arinc_ms: arinc_ms, signs_ui_ms: signs_ui_ms, sign_id: sign_id] ++ extra_logs - ) + log("send_audio", encoded, [arinc_ms: arinc_ms, signs_ui_ms: signs_ui_ms] ++ log_meta) result @@ -160,7 +149,7 @@ defmodule PaEss.HttpUpdater do log( "send_custom_audio", encoded, - [arinc_ms: arinc_ms, signs_ui_ms: signs_ui_ms, sign_id: sign_id] ++ extra_logs + [arinc_ms: arinc_ms, signs_ui_ms: signs_ui_ms] ++ log_meta ) result diff --git a/lib/pa_ess/updater.ex b/lib/pa_ess/updater.ex index d1c0e7233..812126794 100644 --- a/lib/pa_ess/updater.ex +++ b/lib/pa_ess/updater.ex @@ -10,11 +10,21 @@ defmodule PaEss.Updater do scu_id: scu_id, pa_ess_loc: pa_ess_loc, text_zone: text_zone, + default_mode: default_mode, config_engine: config_engine }, top, bottom ) do + log_config = + case config_engine.sign_config(id, default_mode) do + mode when is_atom(mode) -> mode + mode when is_tuple(mode) -> elem(mode, 0) + _ -> nil + end + + log_meta = [sign_id: id, current_config: log_config] + if config_engine.scu_migrated?(scu_id) do pages = zip_pages(top, bottom) @@ -26,10 +36,10 @@ defmodule PaEss.Updater do visual_data: format_pages(pages), expiration: 180, tag: nil - }, [sign_id: id, visual: inspect(pages)]} + }, [visual: inspect(pages)] ++ log_meta} ) else - MessageQueue.update_sign({pa_ess_loc, text_zone}, top, bottom, 180, :now, id) + MessageQueue.update_sign({pa_ess_loc, text_zone}, top, bottom, 180, :now, log_meta) end end @@ -44,8 +54,10 @@ defmodule PaEss.Updater do }, audios, tts_audios, - extra_logs + log_metas ) do + log_metas = Enum.map(log_metas, fn log_meta -> [{:sign_id, id} | log_meta] end) + if config_engine.scu_migrated?(scu_id) do Task.Supervisor.start_child(PaEss.TaskSupervisor, fn -> files = @@ -54,8 +66,8 @@ defmodule PaEss.Updater do end) |> Task.await_many() - Enum.zip([files, tts_audios, extra_logs]) - |> Enum.each(fn {file, {text, pages}, logs} -> + Enum.zip([files, tts_audios, log_metas]) + |> Enum.each(fn {file, {text, pages}, log_meta} -> PaEss.ScuQueue.enqueue_message( scu_id, {:message, scu_id, @@ -66,12 +78,12 @@ defmodule PaEss.Updater do audio_data: [Base.encode64(file)], expiration: 30, tag: nil - }, [sign_id: id, audio: inspect(text), visual: inspect(pages)] ++ logs} + }, [audio: inspect(text), visual: inspect(pages)] ++ log_meta} ) end) end) else - MessageQueue.send_audio({pa_ess_loc, audio_zones}, audios, 5, 60, id, extra_logs) + MessageQueue.send_audio({pa_ess_loc, audio_zones}, audios, 5, 60, log_metas) end end diff --git a/lib/signs/bus.ex b/lib/signs/bus.ex index 383294eec..7803b94ee 100644 --- a/lib/signs/bus.ex +++ b/lib/signs/bus.ex @@ -38,7 +38,7 @@ defmodule Signs.Bus do :last_read_time, :pa_message_plays ] - defstruct @enforce_keys + defstruct @enforce_keys ++ [default_mode: :off] @type t :: %__MODULE__{ id: String.t(), @@ -47,6 +47,7 @@ defmodule Signs.Bus do text_zone: String.t(), audio_zones: [String.t()], max_minutes: integer(), + default_mode: Engine.Config.sign_config(), configs: list(), top_configs: list(), bottom_configs: list(), @@ -149,6 +150,7 @@ defmodule Signs.Bus do %__MODULE__{ id: id, + default_mode: default_mode, configs: configs, config_engine: config_engine, prediction_engine: prediction_engine, @@ -158,7 +160,7 @@ defmodule Signs.Bus do } = state # Fetch the data we need to compute the updated sign content. - config = config_engine.sign_config(id) + config = config_engine.sign_config(id, default_mode) bridge_enabled? = config_engine.chelsea_bridge_config() == :auto bridge_status = bridge_engine.bridge_status() current_time = Timex.now() diff --git a/lib/signs/realtime.ex b/lib/signs/realtime.ex index 0afb2c5af..387de5fc0 100644 --- a/lib/signs/realtime.ex +++ b/lib/signs/realtime.ex @@ -45,6 +45,7 @@ defmodule Signs.Realtime do announced_stalls: [], announced_custom_text: nil, announced_alert: false, + default_mode: :off, prev_prediction_keys: nil, prev_predictions: [], uses_shuttles: true, @@ -64,6 +65,7 @@ defmodule Signs.Realtime do text_zone: String.t(), audio_zones: [String.t()], source_config: SourceConfig.config() | {SourceConfig.config(), SourceConfig.config()}, + default_mode: Engine.Config.sign_config(), current_content_top: Content.Message.value(), current_content_bottom: Content.Message.value(), prediction_engine: module(), @@ -101,6 +103,8 @@ defmodule Signs.Realtime do text_zone: Map.fetch!(config, "text_zone"), audio_zones: Map.fetch!(config, "audio_zones"), source_config: source_config, + default_mode: + config |> Map.get("default_mode") |> then(&if(&1 == "auto", do: :auto, else: :off)), current_content_top: "", current_content_bottom: "", prediction_engine: Engine.Predictions, @@ -145,7 +149,7 @@ defmodule Signs.Realtime do sign_stop_ids = SourceConfig.sign_stop_ids(sign.source_config) sign_routes = SourceConfig.sign_routes(sign.source_config) alert_status = sign.alerts_engine.max_stop_status(sign_stop_ids, sign_routes) - sign_config = sign.config_engine.sign_config(sign.id) + sign_config = sign.config_engine.sign_config(sign.id, sign.default_mode) current_time = sign.current_time_fn.() first_scheduled_departures = diff --git a/priv/signs.json b/priv/signs.json index 0abe383ed..66022335a 100644 --- a/priv/signs.json +++ b/priv/signs.json @@ -4,6 +4,7 @@ "type": "realtime", "pa_ess_loc": "201", "scu_id": "TBR01", + "default_mode": "auto", "read_loop_offset": 120, "text_zone": "m", "audio_zones": [ diff --git a/test/engine/config_test.exs b/test/engine/config_test.exs index 79bdfbb1c..758bedfad 100644 --- a/test/engine/config_test.exs +++ b/test/engine/config_test.exs @@ -7,21 +7,21 @@ defmodule Engine.ConfigTest do Engine.Config.update() Process.sleep(50) - assert Engine.Config.sign_config("chelsea_inbound") == :auto + assert Engine.Config.sign_config("chelsea_inbound", :off) == :auto end test "is off when the sign is disabled" do Engine.Config.update() Process.sleep(50) - assert Engine.Config.sign_config("chelsea_outbound") == :off + assert Engine.Config.sign_config("chelsea_outbound", :auto) == :off end - test "is off when the sign is unspecified" do + test "is the provided default value when the sign is unspecified" do Engine.Config.update() Process.sleep(50) - assert Engine.Config.sign_config("unspecified_sign") == :off + assert Engine.Config.sign_config("unspecified_sign", :headway) == :headway end test "returns custom text when it's not expired" do @@ -33,7 +33,7 @@ defmodule Engine.ConfigTest do end }) - assert Engine.Config.sign_config(state.table_name_signs, "custom_text_test") == + assert Engine.Config.sign_config(state.table_name_signs, "custom_text_test", :off) == {:static_text, {"Test message", "Please ignore"}} end @@ -46,14 +46,14 @@ defmodule Engine.ConfigTest do end }) - assert Engine.Config.sign_config(state.table_name_signs, "custom_text_test") == :auto + assert Engine.Config.sign_config(state.table_name_signs, "custom_text_test", :off) == :auto end test "properly returns headway mode" do Engine.Config.update() Process.sleep(50) - assert Engine.Config.sign_config("headway_test") == :headway + assert Engine.Config.sign_config("headway_test", :off) == :headway end end @@ -66,7 +66,7 @@ defmodule Engine.ConfigTest do test "handles new format of config" do initialize_test_state(%{table_name_signs: :test_new_format, current_version: "new_format"}) - assert Engine.Config.sign_config(:test_new_format, "some_custom_sign") == + assert Engine.Config.sign_config(:test_new_format, "some_custom_sign", :off) == {:static_text, {"custom", ""}} end @@ -89,19 +89,19 @@ defmodule Engine.ConfigTest do test "correctly loads config for a sign with a mode of \"off\"" do initialize_test_state(%{table_name_signs: :config_test_off}) - assert Engine.Config.sign_config(:config_test_off, "off_test") == :off + assert Engine.Config.sign_config(:config_test_off, "off_test", :auto) == :off end test "correctly loads config for a sign with a mode of \"auto\"" do initialize_test_state(%{table_name_signs: :config_test_auto}) - assert Engine.Config.sign_config(:config_test_auto, "auto_test") == :auto + assert Engine.Config.sign_config(:config_test_auto, "auto_test", :off) == :auto end test "correctly loads config for a sign with a mode of \"headway\"" do initialize_test_state(%{table_name_signs: :config_test_headway}) - assert Engine.Config.sign_config(:config_test_headway, "headway_test") == :headway + assert Engine.Config.sign_config(:config_test_headway, "headway_test", :off) == :headway end test "loads chelsea bridge config" do diff --git a/test/message_queue_test.exs b/test/message_queue_test.exs index 40d1dcf9e..6100f98d5 100644 --- a/test/message_queue_test.exs +++ b/test/message_queue_test.exs @@ -49,11 +49,11 @@ defmodule MessageQueueTest do describe "works through public interfaces" do {:ok, pid} = GenServer.start_link(MessageQueue, []) - :ok = MessageQueue.update_sign(pid, 1, 2, 3, 4, 5, "sign_id") - :ok = MessageQueue.send_audio(pid, 1, 2, 3, 4, "sign_id", []) + :ok = MessageQueue.update_sign(pid, 1, 2, 3, 4, 5, []) + :ok = MessageQueue.send_audio(pid, 1, 2, 3, 4, [[]]) - assert MessageQueue.get_message(pid) == {:update_sign, [1, 2, 3, 4, 5, "sign_id"]} - assert MessageQueue.get_message(pid) == {:send_audio, [1, 2, 3, 4, "sign_id", []]} + assert MessageQueue.get_message(pid) == {:update_sign, [1, 2, 3, 4, 5, []]} + assert MessageQueue.get_message(pid) == {:send_audio, [1, 2, 3, 4, [[]]]} assert MessageQueue.get_message(pid) == nil end end diff --git a/test/pa_ess/http_updater_test.exs b/test/pa_ess/http_updater_test.exs index ca7d36a93..186afcee2 100644 --- a/test/pa_ess/http_updater_test.exs +++ b/test/pa_ess/http_updater_test.exs @@ -1,6 +1,6 @@ defmodule Fake.MessageQueue do def get_message do - {:update_sign, [{"SBOX", "c"}, "", "", 60, :now, "sign_id"]} + {:update_sign, [{"SBOX", "c"}, "", "", 60, :now, []]} end end @@ -21,7 +21,7 @@ defmodule PaEss.HttpUpdaterTest do assert {:error, :bad_status} == PaEss.HttpUpdater.process( - {:update_sign, [{"bad_sign", "n"}, "top", "bottom", 60, 1234, "sign_id"]}, + {:update_sign, [{"bad_sign", "n"}, "top", "bottom", 60, 1234, []]}, state ) end @@ -33,7 +33,7 @@ defmodule PaEss.HttpUpdaterTest do capture_log(fn -> assert {:ok, :sent} == PaEss.HttpUpdater.process( - {:update_sign, [{"ABCD", "n"}, "top", "bottom", 60, :now, "sign_id"]}, + {:update_sign, [{"ABCD", "n"}, "top", "bottom", 60, :now, []]}, state ) end) @@ -49,7 +49,7 @@ defmodule PaEss.HttpUpdaterTest do capture_log([level: :info], fn -> assert {:error, :post_error} == PaEss.HttpUpdater.process( - {:update_sign, [{"timeout", "n"}, "top", "bottom", 60, :now, "sign_id"]}, + {:update_sign, [{"timeout", "n"}, "top", "bottom", 60, :now, []]}, state ) end) @@ -62,7 +62,7 @@ defmodule PaEss.HttpUpdaterTest do state = make_state() assert PaEss.HttpUpdater.process( - {:update_sign, [{"SBOX", "c"}, "", "", 60, :now, "sign_id"]}, + {:update_sign, [{"SBOX", "c"}, "", "", 60, :now, []]}, state ) == {:ok, :sent} end @@ -72,7 +72,7 @@ defmodule PaEss.HttpUpdaterTest do assert {:ok, :no_audio} == PaEss.HttpUpdater.process( - {:send_audio, [{"GKEN", ["m"]}, [nil], 5, 60, "sign_id", [[]]]}, + {:send_audio, [{"GKEN", ["m"]}, [nil], 5, 60, [[]]]}, state ) end @@ -88,7 +88,7 @@ defmodule PaEss.HttpUpdaterTest do capture_log(fn -> assert {:ok, :sent} == PaEss.HttpUpdater.process( - {:send_audio, [{"SBOX", ["c"]}, [audio], 5, 60, "sign_id", [[]]]}, + {:send_audio, [{"SBOX", ["c"]}, [audio], 5, 60, [[]]]}, state ) end) @@ -105,7 +105,7 @@ defmodule PaEss.HttpUpdaterTest do capture_log(fn -> assert {:ok, :sent} == PaEss.HttpUpdater.process( - {:send_audio, [{"MCAP", ["n"]}, [audio], 5, 60, "sign_id", [[]]]}, + {:send_audio, [{"MCAP", ["n"]}, [audio], 5, 60, [[]]]}, state ) end) @@ -123,7 +123,7 @@ defmodule PaEss.HttpUpdaterTest do capture_log(fn -> assert {:ok, :sent} = PaEss.HttpUpdater.process( - {:send_audio, [{"MCAP", ["n"]}, [audio], 5, 60, "sign_id", [[]]]}, + {:send_audio, [{"MCAP", ["n"]}, [audio], 5, 60, [[]]]}, state ) end) @@ -139,7 +139,7 @@ defmodule PaEss.HttpUpdaterTest do audio2 = {:canned, {"msg2", ["4021"], :audio}} PaEss.HttpUpdater.process( - {:send_audio, [{"RPRK", ["s"]}, [audio1, audio2], 5, 60, "sign_id", [[], []]]}, + {:send_audio, [{"RPRK", ["s"]}, [audio1, audio2], 5, 60, [[], []]]}, state ) @@ -157,7 +157,7 @@ defmodule PaEss.HttpUpdaterTest do audio = {:canned, {"msg", [], :audio}} PaEss.HttpUpdater.process( - {:send_audio, [{"RPRK", ["m", "s", "c"]}, [audio], 5, 60, "sign_id", [[]]]}, + {:send_audio, [{"RPRK", ["m", "s", "c"]}, [audio], 5, 60, [[]]]}, state ) diff --git a/test/signs/bus_test.exs b/test/signs/bus_test.exs index ea310d7db..ad44c6b15 100644 --- a/test/signs/bus_test.exs +++ b/test/signs/bus_test.exs @@ -69,10 +69,10 @@ defmodule Signs.BusTest do end defmodule FakeConfig do - def sign_config("auto_sign"), do: :auto - def sign_config("off_sign"), do: :off - def sign_config("headway"), do: :headway - def sign_config("static_sign"), do: {:static_text, {"custom", "message"}} + def sign_config("auto_sign", _default), do: :auto + def sign_config("off_sign", _default), do: :off + def sign_config("headway", _default), do: :headway + def sign_config("static_sign", _default), do: {:static_text, {"custom", "message"}} def chelsea_bridge_config(), do: :auto end diff --git a/test/signs/realtime_test.exs b/test/signs/realtime_test.exs index a3828a241..779243372 100644 --- a/test/signs/realtime_test.exs +++ b/test/signs/realtime_test.exs @@ -109,7 +109,7 @@ defmodule Signs.RealtimeTest do describe "run loop" do setup do - stub(Engine.Config.Mock, :sign_config, fn _ -> :auto end) + stub(Engine.Config.Mock, :sign_config, fn _, _ -> :auto end) stub(Engine.Config.Mock, :headway_config, fn _, _ -> @headway_config end) stub(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :none end) stub(Engine.Predictions.Mock, :for_stop, fn _, _ -> [] end) @@ -214,7 +214,10 @@ defmodule Signs.RealtimeTest do end test "when custom text is present, display it, overriding alerts" do - expect(Engine.Config.Mock, :sign_config, fn _ -> {:static_text, {"custom", "message"}} end) + expect(Engine.Config.Mock, :sign_config, fn _, _ -> + {:static_text, {"custom", "message"}} + end) + expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :suspension_closed_station end) expect_messages({"custom", "message"}) expect_audios([{:ad_hoc, {"custom message", :audio}}], [{"custom message", nil}]) @@ -224,11 +227,20 @@ defmodule Signs.RealtimeTest do end test "when sign is disabled, it's empty" do - expect(Engine.Config.Mock, :sign_config, fn _ -> :off end) + expect(Engine.Config.Mock, :sign_config, fn _, _ -> :off end) expect_messages({"", ""}) Signs.Realtime.handle_info(:run_loop, @sign) end + test "when sign has a default mode, uses that when the sign has no mode configured" do + expect(Engine.Config.Mock, :sign_config, fn _, default -> default end) + sign = %{@sign | default_mode: {:static_text, {"default", "message"}}} + + expect_messages({"default", "message"}) + expect_audios([{:ad_hoc, {"default message", :audio}}], [{"default message", nil}]) + Signs.Realtime.handle_info(:run_loop, sign) + end + test "when sign is at a transfer station from a shuttle, and there are no predictions it's empty" do expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :shuttles_transfer_station end) expect_messages({"", ""}) @@ -329,7 +341,7 @@ defmodule Signs.RealtimeTest do end test "when sign is forced into headway mode but no alerts are present, displays headways" do - expect(Engine.Config.Mock, :sign_config, fn _ -> :headway end) + expect(Engine.Config.Mock, :sign_config, fn _, _ -> :headway end) expect(Engine.Config.Mock, :headway_config, fn _, _ -> %{@headway_config | range_high: 14} @@ -344,7 +356,7 @@ defmodule Signs.RealtimeTest do end test "when sign is forced into headway mode but alerts are present, alert takes precedence" do - expect(Engine.Config.Mock, :sign_config, fn _ -> :headway end) + expect(Engine.Config.Mock, :sign_config, fn _, _ -> :headway end) expect(Engine.Predictions.Mock, :for_stop, fn _, _ -> [prediction(destination: :ashmont, arrival: 120)] @@ -961,7 +973,10 @@ defmodule Signs.RealtimeTest do end test "reads custom messages" do - expect(Engine.Config.Mock, :sign_config, fn _ -> {:static_text, {"custom", "message"}} end) + expect(Engine.Config.Mock, :sign_config, fn _, _ -> + {:static_text, {"custom", "message"}} + end) + expect_messages({"custom", "message"}) expect_audios([{:ad_hoc, {"custom message", :audio}}], [{"custom message", nil}]) @@ -1574,7 +1589,7 @@ defmodule Signs.RealtimeTest do describe "Union Sq alert messaging" do setup do - stub(Engine.Config.Mock, :sign_config, fn _ -> :auto end) + stub(Engine.Config.Mock, :sign_config, fn _, _ -> :auto end) stub(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :shuttles_transfer_station end) stub(Engine.Predictions.Mock, :for_stop, fn _, _ -> [] end) stub(Engine.LastTrip.Mock, :is_last_trip?, fn _ -> false end) @@ -1606,7 +1621,7 @@ defmodule Signs.RealtimeTest do describe "Last Trip of the Day" do setup do - stub(Engine.Config.Mock, :sign_config, fn _ -> :auto end) + stub(Engine.Config.Mock, :sign_config, fn _, _ -> :auto end) stub(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :none end) stub(Engine.Predictions.Mock, :for_stop, fn _, _ -> [] end) stub(Engine.LastTrip.Mock, :is_last_trip?, fn _ -> true end) @@ -1774,7 +1789,7 @@ defmodule Signs.RealtimeTest do describe "PA messages" do setup do - stub(Engine.Config.Mock, :sign_config, fn _ -> :auto end) + stub(Engine.Config.Mock, :sign_config, fn _, _ -> :auto end) stub(Engine.Config.Mock, :headway_config, fn _, _ -> @headway_config end) stub(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :none end) stub(Engine.Predictions.Mock, :for_stop, fn _, _ -> [] end)