From 4b94c5b5527c062f85e0915bcb43fb6d590efb8c Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 13 Sep 2017 13:36:58 +0300 Subject: [PATCH] Adding an integration test on memory consumption while a fake edge is adding. --- routing/road_graph.cpp | 6 --- .../routing_integration_tests/CMakeLists.txt | 1 + .../road_graph_tests.cpp | 49 +++++++++++++++++++ .../routing_integration_tests.pro | 1 + .../routing_test_tools.cpp | 10 ++-- .../routing_test_tools.hpp | 1 + .../routing/routing.xcodeproj/project.pbxproj | 4 ++ 7 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 routing/routing_integration_tests/road_graph_tests.cpp diff --git a/routing/road_graph.cpp b/routing/road_graph.cpp index ba1604f1a9..af70d082d3 100644 --- a/routing/road_graph.cpp +++ b/routing/road_graph.cpp @@ -32,12 +32,6 @@ void SplitEdge(Edge const & ab, Junction const & p, vector & edges) auto const & b = ab.GetEndJunction(); // No need to split the edge by its endpoints. - // The "if" condition below fixes the issue which was reproduced if to call: - // @TODO(bykoianko) It's necessary to write a routing integration test and remove comment below. - // std::vector> sourceVicinity; - // Junction j(PointD(50.732084512710564184, -1.2127983570098876953), feature::kDefaultAltitudeMeters); - // FeaturesRoadGraph::FindClosestEdges(j.GetPoint(), 20, sourceVicinity); - // FeaturesRoadGraph::AddFakeEdges(j, sourceVicinity); if (a.GetPoint() == p.GetPoint() || b.GetPoint() == p.GetPoint()) return; diff --git a/routing/routing_integration_tests/CMakeLists.txt b/routing/routing_integration_tests/CMakeLists.txt index 539234a708..39f569c122 100644 --- a/routing/routing_integration_tests/CMakeLists.txt +++ b/routing/routing_integration_tests/CMakeLists.txt @@ -15,6 +15,7 @@ set( get_altitude_test.cpp online_cross_tests.cpp pedestrian_route_test.cpp + road_graph_tests.cpp route_test.cpp routing_test_tools.cpp routing_test_tools.hpp diff --git a/routing/routing_integration_tests/road_graph_tests.cpp b/routing/routing_integration_tests/road_graph_tests.cpp new file mode 100644 index 0000000000..7710d939cd --- /dev/null +++ b/routing/routing_integration_tests/road_graph_tests.cpp @@ -0,0 +1,49 @@ +#include "testing/testing.hpp" + +#include "platform/local_country_file.hpp" + +#include "geometry/point2d.hpp" + +#include "indexer/classificator_loader.hpp" +#include "indexer/feature_altitude.hpp" +#include "indexer/index.hpp" +#include "indexer/mwm_set.hpp" + +#include "routing_common/car_model.hpp" +#include "routing/features_road_graph.hpp" +#include "routing/road_graph.hpp" + +#include "routing_integration_tests/routing_test_tools.hpp" + +#include + +using namespace routing; +using namespace integration; + +// The test on combinatorial explosion of number of fake edges at FeaturesRoadGraph. +// It might happen when a lot of roads intersect at one point. For example, +// http://www.openstreetmap.org/#map=19/50.73197/-1.21295 +UNIT_TEST(FakeEdgesCombinatorialExplosion) +{ + classificator::Load(); + + std::vector localFiles; + GetAllLocalFiles(localFiles); + TEST(!localFiles.empty(), ()); + + Index index; + for (auto const & file : localFiles) + { + auto const result = index.Register(file); + TEST_EQUAL(result.second, MwmSet::RegResult::Success, ()); + } + + FeaturesRoadGraph graph(index, IRoadGraph::Mode::ObeyOnewayTag, + make_shared(CountryParentNameGetterFn())); + Junction const j(m2::PointD(MercatorBounds::FromLatLon(50.73208, -1.21279)), feature::kDefaultAltitudeMeters); + std::vector> sourceVicinity; + graph.FindClosestEdges(j.GetPoint(), 20 /* count */, sourceVicinity); + // In case of the combinatorial explosion mentioned above all the memory was consumed for + // FeaturesRoadGraph::m_fakeIngoingEdges and FeaturesRoadGraph::m_fakeOutgoingEdges fields. + graph.AddFakeEdges(j, sourceVicinity); +} diff --git a/routing/routing_integration_tests/routing_integration_tests.pro b/routing/routing_integration_tests/routing_integration_tests.pro index e93b1c5482..2afd26dbad 100644 --- a/routing/routing_integration_tests/routing_integration_tests.pro +++ b/routing/routing_integration_tests/routing_integration_tests.pro @@ -30,6 +30,7 @@ SOURCES += \ get_altitude_test.cpp \ online_cross_tests.cpp \ pedestrian_route_test.cpp \ + road_graph_tests.cpp \ route_test.cpp \ routing_test_tools.cpp \ street_names_test.cpp \ diff --git a/routing/routing_integration_tests/routing_test_tools.cpp b/routing/routing_integration_tests/routing_test_tools.cpp index bd9b608650..a12e9a2906 100644 --- a/routing/routing_integration_tests/routing_test_tools.cpp +++ b/routing/routing_integration_tests/routing_test_tools.cpp @@ -131,7 +131,7 @@ namespace integration return unique_ptr(move(router)); } - shared_ptr CreateAllMapsComponents(VehicleType vehicleType) + void GetAllLocalFiles(vector & localFiles) { // Setting stored paths from testingmain.cpp Platform & pl = GetPlatform(); @@ -142,12 +142,16 @@ namespace integration pl.SetResourceDir(options.m_resourcePath); platform::migrate::SetMigrationFlag(); - - vector localFiles; platform::FindAllLocalMapsAndCleanup(numeric_limits::max() /* latestVersion */, localFiles); for (auto & file : localFiles) file.SyncWithDisk(); + } + + shared_ptr CreateAllMapsComponents(VehicleType vehicleType) + { + vector localFiles; + GetAllLocalFiles(localFiles); ASSERT(!localFiles.empty(), ()); return make_shared(localFiles, vehicleType); } diff --git a/routing/routing_integration_tests/routing_test_tools.hpp b/routing/routing_integration_tests/routing_test_tools.hpp index ff24268f88..beff191feb 100644 --- a/routing/routing_integration_tests/routing_test_tools.hpp +++ b/routing/routing_integration_tests/routing_test_tools.hpp @@ -92,6 +92,7 @@ private: unique_ptr m_indexRouter; }; +void GetAllLocalFiles(vector & localFiles); void TestOnlineCrosses(ms::LatLon const & startPoint, ms::LatLon const & finalPoint, vector const & expected, IRouterComponents & routerComponents); void TestOnlineFetcher(ms::LatLon const & startPoint, ms::LatLon const & finalPoint, diff --git a/xcode/routing/routing.xcodeproj/project.pbxproj b/xcode/routing/routing.xcodeproj/project.pbxproj index 5d5581ddea..68cc99233a 100644 --- a/xcode/routing/routing.xcodeproj/project.pbxproj +++ b/xcode/routing/routing.xcodeproj/project.pbxproj @@ -100,6 +100,7 @@ 56CA09E61E30E73B00D05C9A /* index_graph_tools.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56CA09E11E30E73B00D05C9A /* index_graph_tools.hpp */; }; 56CA09E71E30E73B00D05C9A /* restriction_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 56CA09E21E30E73B00D05C9A /* restriction_test.cpp */; }; 56CA09E91E30F19800D05C9A /* libtraffic.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 56CA09E81E30F19800D05C9A /* libtraffic.a */; }; + 56CA63071F61206700E6681B /* road_graph_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 56CA63061F61206700E6681B /* road_graph_tests.cpp */; }; 56CC5A371E3884960016AC46 /* cross_mwm_index_graph.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56CC5A361E3884960016AC46 /* cross_mwm_index_graph.hpp */; }; 56D637D61E4B12AA00B86D7B /* cross_mwm_index_graph.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 56D637D51E4B12AA00B86D7B /* cross_mwm_index_graph.cpp */; }; 56EA2FD51D8FD8590083F01A /* routing_helpers.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56EA2FD41D8FD8590083F01A /* routing_helpers.hpp */; }; @@ -377,6 +378,7 @@ 56CA09E11E30E73B00D05C9A /* index_graph_tools.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = index_graph_tools.hpp; sourceTree = ""; }; 56CA09E21E30E73B00D05C9A /* restriction_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = restriction_test.cpp; sourceTree = ""; }; 56CA09E81E30F19800D05C9A /* libtraffic.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtraffic.a; path = "/Users/vladimirbykoyanko/src_github_master/omim/xcode/traffic/../../../omim-build/xcode/Debug/libtraffic.a"; sourceTree = ""; }; + 56CA63061F61206700E6681B /* road_graph_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = road_graph_tests.cpp; sourceTree = ""; }; 56CC5A361E3884960016AC46 /* cross_mwm_index_graph.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cross_mwm_index_graph.hpp; sourceTree = ""; }; 56D637D51E4B12AA00B86D7B /* cross_mwm_index_graph.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cross_mwm_index_graph.cpp; sourceTree = ""; }; 56EA2FD41D8FD8590083F01A /* routing_helpers.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = routing_helpers.hpp; sourceTree = ""; }; @@ -911,6 +913,7 @@ 567E9F721F5850460064CB96 /* bicycle_route_test.cpp */, 567E9F731F5850460064CB96 /* bicycle_turn_test.cpp */, 567E9F741F5850460064CB96 /* turn_test.cpp */, + 56CA63061F61206700E6681B /* road_graph_tests.cpp */, 67BD35AC1C69F086003AA26F /* cross_section_tests.cpp */, 67BD35AD1C69F086003AA26F /* online_cross_tests.cpp */, 67BD35B01C69F086003AA26F /* pedestrian_route_test.cpp */, @@ -1247,6 +1250,7 @@ 674F9BD21B0A580E00704FFA /* road_graph_router.cpp in Sources */, 5694CECE1EBA25F7004576D3 /* vehicle_mask.cpp in Sources */, A1876BC61BB19C4300C9C743 /* speed_camera.cpp in Sources */, + 56CA63071F61206700E6681B /* road_graph_tests.cpp in Sources */, 0C45D7391F2F75500065C3ED /* routing_settings.cpp in Sources */, 0C5FEC691DDE193F0017688C /* road_index.cpp in Sources */, 0CF709361F05172200D5067E /* checkpoints.cpp in Sources */,