Skip to content

Commit

Permalink
Adjusted test
Browse files Browse the repository at this point in the history
  • Loading branch information
micves committed Feb 16, 2024
1 parent 6a3bd7d commit f89032c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/teslamate/vehicles/vehicle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ defmodule TeslaMate.Vehicles.Vehicle do

def handle_event(:info, {:stream, msg}, _state, data)
when msg in [:vehicle_offline] do
Logger.info("Stream reports vehicle as offline, fetching vehicle state ...",
Logger.warning("Stream reports vehicle as offline, fetching vehicle state ...",
car_id: data.car.id
)

Expand Down
28 changes: 5 additions & 23 deletions test/teslamate/vehicles/vehicle/streaming_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -572,22 +572,10 @@ defmodule TeslaMate.Vehicles.Vehicle.StreamingTest do
end

describe "offline" do
test "go offline when stream get :vehicle_offline", %{test: name} do
me = self()

test "fetch state when stream get :vehicle_offline", %{test: name} do
events = [
{:ok, online_event()},
{:ok, online_event()},
{:ok, online_event()},
fn ->
send(me, :continue?)

receive do
:continue -> {:ok, %TeslaApi.Vehicle{state: "offline"}}
after
5_000 -> raise "No :continue after 5s"
end
end,
fn -> Process.sleep(10_000) end
]

Expand All @@ -601,16 +589,10 @@ defmodule TeslaMate.Vehicles.Vehicle.StreamingTest do
assert_receive {ApiMock, {:stream, _eid, func}} when is_function(func)
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online}}}

send(name, {:stream, :vehicle_offline})

assert_receive :continue?
send(:"api_#{name}", :continue)

assert_receive {:start_state, _, :offline, _}
assert_receive {:"$websockex_cast", :disconnect}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :offline}}}

refute_receive _
assert capture_log(@log_opts, fn ->
send(name, {:stream, :vehicle_offline})
refute_receive _
end) =~ "Stream reports vehicle as offline, fetching vehicle state ..."
end
end
end

0 comments on commit f89032c

Please sign in to comment.