From 0014c0bd8d1a44946f68b4aef72b6451de25187a Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Wed, 8 Jul 2015 16:03:45 +0300 Subject: [PATCH] Make MockFileSource behave more like the real one This will help make some bugs more reproducible on the tests as things will happen more asynchronously. --- test/style/mock_file_source.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/style/mock_file_source.cpp b/test/style/mock_file_source.cpp index 6f368bde5..063764523 100644 --- a/test/style/mock_file_source.cpp +++ b/test/style/mock_file_source.cpp @@ -117,11 +117,13 @@ void MockFileSource::Impl::handleRequest(Request* req) { void MockFileSource::Impl::cancelRequest(Request* req) { auto it = std::find(pendingRequests_.begin(), pendingRequests_.end(), req); if (it != pendingRequests_.end()) { - (*it)->destruct(); pendingRequests_.erase(it); } else { - EXPECT_TRUE(false) << "Should never be reached."; + // There is no request for this URL anymore. Likely, the request already completed + // before we got around to process the cancelation request. } + + req->destruct(); } void MockFileSource::Impl::dispatchPendingRequests() { @@ -142,7 +144,7 @@ void MockFileSource::setOnRequestDelayedCallback(std::function callb Request* MockFileSource::request(const Resource& resource, uv_loop_t* loop, Callback callback) { Request* req = new Request(resource, loop, std::move(callback)); - thread_->invokeSync(&Impl::handleRequest, req); + thread_->invoke(&Impl::handleRequest, req); return req; }