diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-06-10 21:28:29 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-06-21 18:58:48 +0200 |
commit | 2be2340c303f018ba3a6661708051811e4cdbb70 (patch) | |
tree | 1059a8f301d99f8bc1610a01ea17db49f0f37738 /test/src | |
parent | b06176cf116eefb821f9d51c89c9c6bad6b67d41 (diff) | |
download | qtlocation-mapboxgl-2be2340c303f018ba3a6661708051811e4cdbb70.tar.gz |
[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.
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/mbgl/test/stub_file_source.cpp | 15 | ||||
-rw-r--r-- | test/src/mbgl/test/stub_file_source.hpp | 3 |
2 files changed, 14 insertions, 4 deletions
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<Response> 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<AsyncRequest> 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<Response> 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<AsyncRequest> request(const Resource&, Callback) override; + void remove(AsyncRequest*); using ResponseFunction = std::function<optional<Response> (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<Response> defaultResponse(const Resource&); |