From 1c2405a9ccc2d136802e01ba5e39b9172f493b3c Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Mon, 8 Oct 2018 11:21:40 +0300 Subject: [PATCH] Fixed tests and worker thread --- base/worker_thread.cpp | 5 +++-- base/worker_thread.hpp | 2 +- editor/editor_tests/osm_editor_test.cpp | 11 +++++++++-- platform/platform_tests_support/async_gui_thread.hpp | 3 ++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/base/worker_thread.cpp b/base/worker_thread.cpp index 9c0bb41c59..85da0a1d96 100644 --- a/base/worker_thread.cpp +++ b/base/worker_thread.cpp @@ -6,7 +6,8 @@ using namespace std; namespace base { -WorkerThread::WorkerThread(size_t threadsCount) +WorkerThread::WorkerThread(size_t threadsCount /* = 1 */, Exit e /* = Exit::SkipPending */) + : m_exit(e) { for (size_t i = 0; i < threadsCount; ++i) m_threads.emplace_back(threads::SimpleThread(&WorkerThread::ProcessTasks, this)); @@ -143,7 +144,7 @@ bool WorkerThread::Shutdown(Exit e) void WorkerThread::ShutdownAndJoin() { ASSERT(m_checker.CalledOnOriginalThread(), ()); - Shutdown(Exit::SkipPending); + Shutdown(m_exit); for (auto & thread : m_threads) { if (thread.joinable()) diff --git a/base/worker_thread.hpp b/base/worker_thread.hpp index 147cfc2353..05e4032bb3 100644 --- a/base/worker_thread.hpp +++ b/base/worker_thread.hpp @@ -31,7 +31,7 @@ public: SkipPending }; - explicit WorkerThread(size_t threadsCount = 1); + explicit WorkerThread(size_t threadsCount = 1, Exit e = Exit::SkipPending); ~WorkerThread() override; // Pushes task to the end of the thread's queue of immediate tasks. diff --git a/editor/editor_tests/osm_editor_test.cpp b/editor/editor_tests/osm_editor_test.cpp index c829883b54..9516ab7dbd 100644 --- a/editor/editor_tests/osm_editor_test.cpp +++ b/editor/editor_tests/osm_editor_test.cpp @@ -14,6 +14,7 @@ #include "indexer/ftypes_matcher.hpp" #include "indexer/scales.hpp" +#include "platform/platform_tests_support/async_gui_thread.hpp" #include "platform/platform_tests_support/scoped_file.hpp" #include "coding/file_name_utils.hpp" @@ -607,7 +608,10 @@ void EditorTest::OnMapDeregisteredTest() TEST(!editor.m_features.Get()->empty(), ()); TEST_EQUAL(editor.m_features.Get()->size(), 2, ()); - editor.OnMapDeregistered(gbMwmId.GetInfo()->GetLocalFile()); + { + platform::tests_support::AsyncGuiThread guiThread; + editor.OnMapDeregistered(gbMwmId.GetInfo()->GetLocalFile()); + } TEST_EQUAL(editor.m_features.Get()->size(), 1, ()); auto const editedMwmId = editor.m_features.Get()->find(rfMwmId); @@ -1251,7 +1255,10 @@ void EditorTest::SaveTransactionTest() } { - editor.OnMapDeregistered(mwmId.GetInfo()->GetLocalFile()); + { + platform::tests_support::AsyncGuiThread guiThread; + editor.OnMapDeregistered(mwmId.GetInfo()->GetLocalFile()); + } auto const features = editor.m_features.Get(); auto const mwmIt = features->find(mwmId); diff --git a/platform/platform_tests_support/async_gui_thread.hpp b/platform/platform_tests_support/async_gui_thread.hpp index c7a00686bb..c77f95f58c 100644 --- a/platform/platform_tests_support/async_gui_thread.hpp +++ b/platform/platform_tests_support/async_gui_thread.hpp @@ -16,7 +16,8 @@ class AsyncGuiThread public: AsyncGuiThread() { - GetPlatform().SetGuiThread(std::make_unique()); + GetPlatform().SetGuiThread(std::make_unique( + 1 /* threadsCount */, base::WorkerThread::Exit::ExecPending)); } virtual ~AsyncGuiThread()