From 2be2340c303f018ba3a6661708051811e4cdbb70 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Fri, 10 Jun 2016 21:28:29 +0300 Subject: [tests] Do not re-trigger answered requests This happens on real file sources when tiles expire or in case of error. Here we only retry on error. --- test/src/mbgl/test/stub_file_source.cpp | 15 +++++++++++++-- test/src/mbgl/test/stub_file_source.hpp | 3 +-- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'test/src') diff --git a/test/src/mbgl/test/stub_file_source.cpp b/test/src/mbgl/test/stub_file_source.cpp index 7b92fd253f..75d7e2d072 100644 --- a/test/src/mbgl/test/stub_file_source.cpp +++ b/test/src/mbgl/test/stub_file_source.cpp @@ -11,20 +11,24 @@ public: } ~StubFileRequest() override { - fileSource.pending.erase(this); + fileSource.remove(this); } StubFileSource& fileSource; }; StubFileSource::StubFileSource() { - timer.start(10ms, 10ms, [this] { + timer.start(1ms, 1ms, [this] { // Explicit copy to avoid iterator invalidation if ~StubFileRequest gets called within the loop. auto pending_ = pending; for (auto& pair : pending_) { optional res = std::get<1>(pair.second)(std::get<0>(pair.second)); if (res) { std::get<2>(pair.second)(*res); + + if (!res->error) { + remove(pair.first); + } } } }); @@ -38,6 +42,13 @@ std::unique_ptr StubFileSource::request(const Resource& resource, return std::move(req); } +void StubFileSource::remove(AsyncRequest* req) { + auto it = pending.find(req); + if (it != pending.end()) { + pending.erase(it); + } +} + optional StubFileSource::defaultResponse(const Resource& resource) { switch (resource.kind) { case Resource::Kind::Style: diff --git a/test/src/mbgl/test/stub_file_source.hpp b/test/src/mbgl/test/stub_file_source.hpp index b88fb59907..ee4175cc3f 100644 --- a/test/src/mbgl/test/stub_file_source.hpp +++ b/test/src/mbgl/test/stub_file_source.hpp @@ -13,6 +13,7 @@ public: ~StubFileSource() override; std::unique_ptr request(const Resource&, Callback) override; + void remove(AsyncRequest*); using ResponseFunction = std::function (const Resource&)>; @@ -30,8 +31,6 @@ public: ResponseFunction spriteImageResponse; private: - friend class StubFileRequest; - // The default behavior is to throw if no per-kind callback has been set. optional defaultResponse(const Resource&); -- cgit v1.2.1