forked from organicmaps/organicmaps
[search] Followup fixes to TestSearchRequest.
This commit is contained in:
parent
5f7012dead
commit
d7075b437d
3 changed files with 27 additions and 30 deletions
|
@ -317,7 +317,7 @@ void CheckCompleteness(string const & path, m2::RectD const & viewport, TestSear
|
|||
|
||||
for (auto & q : queries)
|
||||
{
|
||||
q.m_request->Wait();
|
||||
q.m_request->Run();
|
||||
|
||||
LOG(LDEBUG, (q.m_query, q.m_request->Results()));
|
||||
int pos =
|
||||
|
@ -459,7 +459,7 @@ int main(int argc, char * argv[])
|
|||
vector<double> responseTimes(queries.size());
|
||||
for (size_t i = 0; i < queries.size(); ++i)
|
||||
{
|
||||
requests[i]->Wait();
|
||||
requests[i]->Run();
|
||||
auto rt = duration_cast<milliseconds>(requests[i]->ResponseTime()).count();
|
||||
responseTimes[i] = static_cast<double>(rt) / 1000;
|
||||
PrintTopResults(MakePrefixFree(queries[i]), requests[i]->Results(), FLAGS_top,
|
||||
|
|
|
@ -41,16 +41,6 @@ TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & q
|
|||
m_params.m_onResults = move(onResults);
|
||||
}
|
||||
|
||||
void TestSearchRequest::Start() { m_engine.Search(m_params, m_viewport); }
|
||||
void TestSearchRequest::Wait()
|
||||
{
|
||||
unique_lock<mutex> lock(m_mu);
|
||||
m_cv.wait(lock, [this]()
|
||||
{
|
||||
return m_done;
|
||||
});
|
||||
}
|
||||
|
||||
void TestSearchRequest::Run()
|
||||
{
|
||||
Start();
|
||||
|
@ -71,20 +61,23 @@ vector<search::Result> const & TestSearchRequest::Results() const
|
|||
return m_results;
|
||||
}
|
||||
|
||||
void TestSearchRequest::Start()
|
||||
{
|
||||
m_engine.Search(m_params, m_viewport);
|
||||
}
|
||||
|
||||
void TestSearchRequest::Wait()
|
||||
{
|
||||
unique_lock<mutex> lock(m_mu);
|
||||
m_cv.wait(lock, [this]() { return m_done; });
|
||||
}
|
||||
|
||||
void TestSearchRequest::SetUpCallbacks()
|
||||
{
|
||||
m_params.m_onStarted = bind(&TestSearchRequest::OnStarted, this);
|
||||
m_params.m_onResults = bind(&TestSearchRequest::OnResults, this, _1);
|
||||
}
|
||||
|
||||
void TestSearchRequest::SetCustomOnResults(SearchParams::TOnResults const & customOnResults)
|
||||
{
|
||||
m_params.m_onResults = [this, customOnResults](search::Results const & results) {
|
||||
OnResults(results);
|
||||
customOnResults(results);
|
||||
};
|
||||
}
|
||||
|
||||
void TestSearchRequest::OnStarted()
|
||||
{
|
||||
lock_guard<mutex> lock(m_mu);
|
||||
|
@ -105,5 +98,10 @@ void TestSearchRequest::OnResults(search::Results const & results)
|
|||
m_results.assign(results.begin(), results.end());
|
||||
}
|
||||
}
|
||||
|
||||
void TestSearchRequest::SetCustomOnResults(SearchParams::TOnResults const & onResults)
|
||||
{
|
||||
m_params.m_onResults = onResults;
|
||||
}
|
||||
} // namespace tests_support
|
||||
} // namespace search
|
||||
|
|
|
@ -28,19 +28,9 @@ public:
|
|||
Mode mode, m2::RectD const & viewport);
|
||||
TestSearchRequest(TestSearchEngine & engine, SearchParams params, m2::RectD const & viewport);
|
||||
|
||||
// Initiates the search.
|
||||
void Start();
|
||||
|
||||
// Waits for the search to finish.
|
||||
void Wait();
|
||||
|
||||
// Initiates the search and waits for it to finish.
|
||||
void Run();
|
||||
|
||||
// Sets the onResults callback without breaking the synchronization
|
||||
// introduced by OnResults().
|
||||
void SetCustomOnResults(SearchParams::TOnResults const & customOnResults);
|
||||
|
||||
// Call these functions only after call to Wait().
|
||||
steady_clock::duration ResponseTime() const;
|
||||
vector<search::Result> const & Results() const;
|
||||
|
@ -50,11 +40,20 @@ protected:
|
|||
Mode mode, m2::RectD const & viewport, SearchParams::TOnStarted onStarted,
|
||||
SearchParams::TOnResults onResults);
|
||||
|
||||
// Initiates the search.
|
||||
void Start();
|
||||
|
||||
// Waits for the search to finish.
|
||||
void Wait();
|
||||
|
||||
void SetUpCallbacks();
|
||||
|
||||
void OnStarted();
|
||||
void OnResults(search::Results const & results);
|
||||
|
||||
// Overrides the default onResults callback.
|
||||
void SetCustomOnResults(SearchParams::TOnResults const & onResults);
|
||||
|
||||
condition_variable m_cv;
|
||||
mutable mutex m_mu;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue