diff --git a/map/framework.hpp b/map/framework.hpp index ba8ca0e0d8..a86124a048 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -147,7 +147,7 @@ class Framework : public SearchAPI::Delegate, public RoutingManager::Delegate #endif private: - // Must be first member in Framework. + // Must be first member in Framework and must be destroyed first in Framework destructor. unique_ptr m_threadRunner = make_unique(); protected: diff --git a/map/map_tests/booking_filter_test.cpp b/map/map_tests/booking_filter_test.cpp index 2c34ce44ad..7b468d8bc8 100644 --- a/map/map_tests/booking_filter_test.cpp +++ b/map/map_tests/booking_filter_test.cpp @@ -7,6 +7,8 @@ #include "partners_api/booking_api.hpp" +#include "platform/platform.hpp" + #include "search/result.hpp" #include "indexer/feature_meta.hpp" @@ -40,6 +42,7 @@ protected: private: storage::CountryInfoGetterForTesting m_infoGetter; + Platform::ThreadRunner m_runner; }; UNIT_CLASS_TEST(TestMwmEnvironment, BookingFilter_AvailabilitySmoke) diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp index 47d4d5c6c4..4eaa0b9562 100644 --- a/map/map_tests/bookmarks_test.cpp +++ b/map/map_tests/bookmarks_test.cpp @@ -21,6 +21,8 @@ using namespace std; namespace { +using Runner = Platform::ThreadRunner; + static FrameworkParams const kFrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */); char const * kmlString = @@ -563,7 +565,7 @@ char const * kmlString2 = ""; } -UNIT_TEST(Bookmarks_InnerFolder) +UNIT_CLASS_TEST(Runner, Bookmarks_InnerFolder) { BookmarkManager bmManager((BookmarkManager::Callbacks(bmCallbacks))); BookmarkManager::KMLDataCollection kmlDataCollection; @@ -575,7 +577,7 @@ UNIT_TEST(Bookmarks_InnerFolder) TEST_EQUAL(bmManager.GetUserMarkIds(groupIds.front()).size(), 1, ()); } -UNIT_TEST(BookmarkCategory_EmptyName) +UNIT_CLASS_TEST(Runner, BookmarkCategory_EmptyName) { BookmarkManager bmManager((BookmarkManager::Callbacks(bmCallbacks))); auto const catId = bmManager.CreateBookmarkCategory("", false /* autoSave */); @@ -628,7 +630,7 @@ char const * kmlString3 = } } -UNIT_TEST(Bookmarks_SpecialXMLNames) +UNIT_CLASS_TEST(Runner, Bookmarks_SpecialXMLNames) { BookmarkManager bmManager((BookmarkManager::Callbacks(bmCallbacks))); BookmarkManager::KMLDataCollection kmlDataCollection; @@ -667,7 +669,7 @@ UNIT_TEST(Bookmarks_SpecialXMLNames) TEST(my::DeleteFileX(fileName), ()); } -UNIT_TEST(TrackParsingTest_1) +UNIT_CLASS_TEST(Runner, TrackParsingTest_1) { string const kmlFile = GetPlatform().TestsDataPathForFile("kml-with-track-kml.test"); BookmarkManager bmManager((BookmarkManager::Callbacks(bmCallbacks))); @@ -699,7 +701,7 @@ UNIT_TEST(TrackParsingTest_1) } } -UNIT_TEST(TrackParsingTest_2) +UNIT_CLASS_TEST(Runner, TrackParsingTest_2) { string const kmlFile = GetPlatform().TestsDataPathForFile("kml-with-track-from-google-earth.test"); BookmarkManager bmManager((BookmarkManager::Callbacks(bmCallbacks))); @@ -718,7 +720,7 @@ UNIT_TEST(TrackParsingTest_2) TEST_EQUAL(track->GetColor(0), dp::Color(57, 255, 32, 255), ()); } -UNIT_TEST(Bookmarks_Listeners) +UNIT_CLASS_TEST(Runner, Bookmarks_Listeners) { set createdMarksResult; set updatedMarksResult; diff --git a/partners_api/partners_api_tests/async_gui_thread.hpp b/partners_api/partners_api_tests/async_gui_thread.hpp index df2b0ad78a..5291edfbb4 100644 --- a/partners_api/partners_api_tests/async_gui_thread.hpp +++ b/partners_api/partners_api_tests/async_gui_thread.hpp @@ -20,5 +20,8 @@ public: { GetPlatform().SetGuiThread(my::make_unique()); } + +private: + Platform::ThreadRunner m_runner; }; } // namespace partners_api diff --git a/partners_api/partners_api_tests/uber_tests.cpp b/partners_api/partners_api_tests/uber_tests.cpp index 974222f628..d7ddf11471 100644 --- a/partners_api/partners_api_tests/uber_tests.cpp +++ b/partners_api/partners_api_tests/uber_tests.cpp @@ -16,6 +16,8 @@ using namespace taxi; namespace { +using Runner = Platform::ThreadRunner; + bool IsComplete(Product const & product) { return !product.m_productId.empty() && !product.m_name.empty() && !product.m_time.empty() && @@ -165,7 +167,7 @@ UNIT_TEST(Uber_ProductMaker) }, errorCallback); } -UNIT_TEST(Uber_GetAvailableProducts) +UNIT_CLASS_TEST(Runner, Uber_GetAvailableProducts) { taxi::uber::Api api("http://localhost:34568/partners"); ms::LatLon const from(55.796918, 37.537859); diff --git a/partners_api/partners_api_tests/yandex_tests.cpp b/partners_api/partners_api_tests/yandex_tests.cpp index 622ca4444d..ae821f8352 100644 --- a/partners_api/partners_api_tests/yandex_tests.cpp +++ b/partners_api/partners_api_tests/yandex_tests.cpp @@ -8,6 +8,8 @@ namespace { +using Runner = Platform::ThreadRunner; + UNIT_TEST(Yandex_GetTaxiInfo) { ms::LatLon const from(55.796918, 37.537859); @@ -19,7 +21,7 @@ UNIT_TEST(Yandex_GetTaxiInfo) TEST(!result.empty(), ()); } -UNIT_TEST(Yandex_GetAvailableProducts) +UNIT_CLASS_TEST(Runner, Yandex_GetAvailableProducts) { taxi::yandex::Api api("http://localhost:34568/partners"); ms::LatLon const from(55.796918, 37.537859); diff --git a/platform/platform.hpp b/platform/platform.hpp index 03b9bc4faa..577215bdf9 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -37,12 +37,14 @@ extern Platform & GetPlatform(); class Platform { public: - friend struct ThreadRunner; + friend class ThreadRunner; - struct ThreadRunner + // ThreadRunner may be subclassed for testing purposes. + class ThreadRunner { + public: ThreadRunner() { GetPlatform().RunThreads(); } - ~ThreadRunner() { GetPlatform().ShutdownThreads(); } + virtual ~ThreadRunner() { GetPlatform().ShutdownThreads(); } }; enum EError diff --git a/storage/storage_integration_tests/storage_downloading_tests.cpp b/storage/storage_integration_tests/storage_downloading_tests.cpp index 6dc668b21b..3b8d67b84d 100644 --- a/storage/storage_integration_tests/storage_downloading_tests.cpp +++ b/storage/storage_integration_tests/storage_downloading_tests.cpp @@ -25,6 +25,8 @@ using namespace storage; namespace { +using Runner = Platform::ThreadRunner; + string const kCountryId = "Angola"; class InterruptException : public exception {}; @@ -70,13 +72,11 @@ UNIT_TEST(SmallMwms_ReDownloadExistedMWMIgnored_Test) TEST(!storage.IsDownloadInProgress(), ()); } -UNIT_TEST(SmallMwms_InterruptDownloadResumeDownload_Test) +UNIT_CLASS_TEST(Runner, SmallMwms_InterruptDownloadResumeDownload_Test) { - auto runner = make_unique(); WritableDirChanger writableDirChanger(kMapTestDir); // Start download but interrupt it - { Storage storage(COUNTRIES_FILE); TEST(version::IsSingleMwm(storage.GetCurrentDataVersion()), ()); @@ -99,7 +99,6 @@ UNIT_TEST(SmallMwms_InterruptDownloadResumeDownload_Test) } // Continue download - { Storage storage(COUNTRIES_FILE);