Offline routing phase 1: valhalla container building from the offline map's extracts, status in the Offline data panel
This commit is contained in:
1 parent
6f5f11cb4d
commit
bf912b96e5
13 files changed
+455
-36
No files matched your search
@@ -69,6 +69,7 @@ module AppTestHelper
|
||||
File.write(File.join(Maptool::App::DATA_DIR, "livetrack.json"), "[]")
|
||||
FileUtils.rm_f(File.join(Maptool::App::DATA_DIR, "offline_regions.json"))
|
||||
Maptool::PmtilesBuilder.reset!
|
||||
Maptool::Routing.reset!
|
||||
super
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
require_relative "test_helper"
|
||||
require "maptool/routing"
|
||||
|
||||
class RoutingTest < Minitest::Test
|
||||
def setup
|
||||
@data = Dir.mktmpdir
|
||||
@routing = File.join(@data, "routing")
|
||||
FileUtils.mkdir_p([@routing, File.join(@data, "geofabrik_cache")])
|
||||
Maptool::PmtilesBuilder.set_selected_regions(@data, %w[SK])
|
||||
end
|
||||
|
||||
def teardown
|
||||
FileUtils.remove_entry(@data)
|
||||
Maptool::PmtilesBuilder.reset!
|
||||
Maptool::Routing.reset!
|
||||
end
|
||||
|
||||
def test_a_build_needs_the_extracts_and_writes_a_request_for_the_container
|
||||
assert_raises(Maptool::PmtilesBuilder::BuildError) { Maptool::Routing.request_build(@data) }
|
||||
|
||||
File.write(File.join(@data, "geofabrik_cache", "SK.osm.pbf"), "pbf")
|
||||
Maptool::Routing.request_build(@data)
|
||||
assert_equal %w[SK], JSON.parse(File.read(File.join(@routing, "build-request.json")))["regions"]
|
||||
assert_equal "waiting for the routing container", Maptool::Routing.build_status(@data)[:step]
|
||||
end
|
||||
|
||||
def test_a_request_during_an_offline_build_waits_for_it
|
||||
Maptool::PmtilesBuilder::OFFLINE_STATUS.replace(state: "running")
|
||||
Maptool::Routing.request_build(@data)
|
||||
assert_equal "waiting for the offline map build", Maptool::Routing.build_status(@data)[:step]
|
||||
refute File.exist?(File.join(@routing, "build-request.json"))
|
||||
|
||||
Maptool::PmtilesBuilder::OFFLINE_STATUS.replace(state: "done")
|
||||
File.write(File.join(@data, "geofabrik_cache", "SK.osm.pbf"), "pbf")
|
||||
Maptool::Routing.offline_build_finished(@data)
|
||||
assert File.exist?(File.join(@routing, "build-request.json"))
|
||||
end
|
||||
|
||||
def test_update_check_compares_regions_and_extract_age
|
||||
assert_nil Maptool::Routing.update_available?(@data)
|
||||
|
||||
pbf = File.join(@data, "geofabrik_cache", "SK.osm.pbf")
|
||||
File.write(pbf, "pbf")
|
||||
File.utime(Time.now - 60, Time.now - 60, pbf)
|
||||
File.write(File.join(@routing, "tiles.tar"), "tiles")
|
||||
File.write(File.join(@routing, "built.json"), JSON.generate(regions: %w[SK]))
|
||||
refute Maptool::Routing.update_available?(@data)
|
||||
|
||||
File.utime(Time.now + 60, Time.now + 60, pbf)
|
||||
assert Maptool::Routing.update_available?(@data)
|
||||
Maptool::PmtilesBuilder.set_selected_regions(@data, %w[SK CZ])
|
||||
assert Maptool::Routing.update_available?(@data)
|
||||
assert_equal [{ code: "SK" }], Maptool::Routing.tiles_status(@data, "")[:meta][:sources]
|
||||
end
|
||||
|
||||
def test_the_container_status_file_is_passed_through
|
||||
assert_equal({ state: "idle" }, Maptool::Routing.build_status(@data))
|
||||
File.write(File.join(@routing, "status.json"), JSON.generate(state: "running", step: "packing tiles"))
|
||||
assert_equal "packing tiles", Maptool::Routing.build_status(@data)[:step]
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user