mirror of
https://github.com/teslamate-org/teslamate.git
synced 2026-01-24 21:06:08 +08:00
Update srtm to 0.8.0
This commit is contained in:
@@ -10,8 +10,8 @@ defmodule SRTMMock do
|
||||
GenServer.start_link(__MODULE__, opts, name: Keyword.fetch!(opts, :name))
|
||||
end
|
||||
|
||||
def get_elevation(name, client, lat, lng) do
|
||||
GenServer.call(name, {:get_elevation, client, lat, lng})
|
||||
def get_elevation(name, lat, lng, opts \\ []) do
|
||||
GenServer.call(name, {:get_elevation, lat, lng, opts})
|
||||
end
|
||||
|
||||
# Callbacks
|
||||
@@ -22,15 +22,15 @@ defmodule SRTMMock do
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_call({:get_elevation, client, lat, lng}, _, %State{responses: r} = state) do
|
||||
def handle_call({:get_elevation, lat, lng, opts}, _, %State{responses: r} = state) do
|
||||
lat = with %Decimal{} <- lat, do: Decimal.to_float(lat)
|
||||
lng = with %Decimal{} <- lng, do: Decimal.to_float(lng)
|
||||
|
||||
send(state.pid, {SRTM, {:get_elevation, client, lat, lng}})
|
||||
send(state.pid, {SRTM, {:get_elevation, lat, lng, opts}})
|
||||
|
||||
response =
|
||||
with {:ok, elevation} <- Map.fetch!(r, {lat, lng}).() do
|
||||
{:ok, elevation, client}
|
||||
{:ok, elevation}
|
||||
end
|
||||
|
||||
{:reply, response, state}
|
||||
|
||||
@@ -46,9 +46,9 @@ defmodule TeslaMate.Terrain.UpdatePositionsTest do
|
||||
|
||||
for {_, i} <- Enum.with_index(positions) do
|
||||
if i in [50, 150] do
|
||||
assert_receive {SRTM, {:get_elevation, %SRTM.Client{}, 1.0, 1.0}}
|
||||
assert_receive {SRTM, {:get_elevation, 1.0, 1.0, _opts}}
|
||||
else
|
||||
assert_receive {SRTM, {:get_elevation, %SRTM.Client{}, 0.0, 0.0}}
|
||||
assert_receive {SRTM, {:get_elevation, 0.0, 0.0, _opts}}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -101,10 +101,10 @@ defmodule TeslaMate.Terrain.UpdatePositionsTest do
|
||||
end
|
||||
})
|
||||
|
||||
assert_receive {SRTM, {:get_elevation, %SRTM.Client{}, 0.0, 0.0}}
|
||||
assert_receive {SRTM, {:get_elevation, %SRTM.Client{}, 1.0, 1.0}}
|
||||
assert_receive {SRTM, {:get_elevation, %SRTM.Client{}, 42.0, 42.0}}
|
||||
assert_receive {SRTM, {:get_elevation, %SRTM.Client{}, 42.0, 42.0}}
|
||||
assert_receive {SRTM, {:get_elevation, 0.0, 0.0, _opts}}
|
||||
assert_receive {SRTM, {:get_elevation, 1.0, 1.0, _opts}}
|
||||
assert_receive {SRTM, {:get_elevation, 42.0, 42.0, _opts}}
|
||||
assert_receive {SRTM, {:get_elevation, 42.0, 42.0, _opts}}
|
||||
|
||||
# 4th and 5th are :unavailable
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ defmodule TeslaMate.TerrainTest do
|
||||
:ok = start_terrain(name, %{{0, 0} => fn -> {:ok, 42} end})
|
||||
|
||||
assert 42 == Terrain.get_elevation(name, {0, 0})
|
||||
assert_received {SRTM, {:get_elevation, %SRTM.Client{}, 0, 0}}
|
||||
assert_received {SRTM, {:get_elevation, 0, 0, [disk_cache_path: ".srtm_cache"]}}
|
||||
|
||||
refute_receive _
|
||||
end
|
||||
@@ -40,7 +40,7 @@ defmodule TeslaMate.TerrainTest do
|
||||
assert Terrain.get_elevation(name, {0, 0}) == nil
|
||||
|
||||
TestHelper.eventually(fn ->
|
||||
assert_received {SRTM, {:get_elevation, %SRTM.Client{}, 0, 0}}
|
||||
assert_received {SRTM, {:get_elevation, 0, 0, _opts}}
|
||||
end)
|
||||
|
||||
refute_receive _
|
||||
@@ -58,7 +58,7 @@ defmodule TeslaMate.TerrainTest do
|
||||
assert Terrain.get_elevation(name, {0, 0}) == nil
|
||||
|
||||
TestHelper.eventually(fn ->
|
||||
assert_received {SRTM, {:get_elevation, %SRTM.Client{}, 0, 0}}
|
||||
assert_received {SRTM, {:get_elevation, 0, 0, _opts}}
|
||||
end)
|
||||
|
||||
# still blocked
|
||||
@@ -80,7 +80,7 @@ defmodule TeslaMate.TerrainTest do
|
||||
assert Terrain.get_elevation(name, {1, 1}) == nil
|
||||
|
||||
TestHelper.eventually(fn ->
|
||||
assert_received {SRTM, {:get_elevation, %SRTM.Client{}, 1, 1}}
|
||||
assert_received {SRTM, {:get_elevation, 1, 1, _opts}}
|
||||
end)
|
||||
|
||||
refute_receive _
|
||||
@@ -102,9 +102,9 @@ defmodule TeslaMate.TerrainTest do
|
||||
# circuit broke after 3 attempts
|
||||
TestHelper.eventually(
|
||||
fn ->
|
||||
assert_received {SRTM, {:get_elevation, %SRTM.Client{}, 0, 0}}
|
||||
assert_received {SRTM, {:get_elevation, %SRTM.Client{}, 0, 0}}
|
||||
assert_received {SRTM, {:get_elevation, %SRTM.Client{}, 0, 0}}
|
||||
assert_received {SRTM, {:get_elevation, 0, 0, _opts}}
|
||||
assert_received {SRTM, {:get_elevation, 0, 0, _opts}}
|
||||
assert_received {SRTM, {:get_elevation, 0, 0, _opts}}
|
||||
end,
|
||||
attempts: 25
|
||||
)
|
||||
@@ -112,14 +112,4 @@ defmodule TeslaMate.TerrainTest do
|
||||
refute_receive _
|
||||
end
|
||||
end
|
||||
|
||||
describe "handle_info/2" do
|
||||
test "handles :purge_srtm_in_memory_cache message", %{test: name} do
|
||||
:ok = start_terrain(name)
|
||||
|
||||
send(name, :purge_srtm_in_memory_cache)
|
||||
|
||||
refute_receive _
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user