summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHuyen Chau Nguyen <hello@chau-nguyen.de>2018-10-31 09:51:50 +0100
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2018-11-15 12:19:48 -0800
commit8d0b06d5dd73313724bf5186a244f3ad3e7ba85e (patch)
treeeea5e5c0d397a78ca2e61a93a4f4087bc2537aa1 /test
parent9a606caf0b33d5dba33e33ce3fb59724e1849eb1 (diff)
downloadqtlocation-mapboxgl-8d0b06d5dd73313724bf5186a244f3ad3e7ba85e.tar.gz
[core] add test about number of maximum concurrent requests
Diffstat (limited to 'test')
-rw-r--r--test/src/mbgl/test/fake_file_source.hpp14
-rw-r--r--test/src/mbgl/test/stub_file_source.hpp14
-rw-r--r--test/storage/offline_download.test.cpp6
-rw-r--r--test/storage/online_file_source.test.cpp9
4 files changed, 40 insertions, 3 deletions
diff --git a/test/src/mbgl/test/fake_file_source.hpp b/test/src/mbgl/test/fake_file_source.hpp
index baae7f9b7e..8803e9576b 100644
--- a/test/src/mbgl/test/fake_file_source.hpp
+++ b/test/src/mbgl/test/fake_file_source.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/storage/file_source.hpp>
+#include <mbgl/storage/online_file_source.hpp>
#include <algorithm>
#include <list>
@@ -56,6 +57,19 @@ public:
}
std::list<FakeFileRequest*> requests;
+
+};
+
+class FakeOnlineFileSource : public OnlineFileSource, public FakeFileSource {
+public:
+ std::unique_ptr<AsyncRequest> request(const Resource& resource, Callback callback) override {
+ return FakeFileSource::request(resource, callback);
+ }
+
+ bool respond(Resource::Kind kind, const Response& response) {
+ return FakeFileSource::respond(kind, response);
+ }
};
+
} // namespace mbgl
diff --git a/test/src/mbgl/test/stub_file_source.hpp b/test/src/mbgl/test/stub_file_source.hpp
index 6cee8377c6..1135fa9a80 100644
--- a/test/src/mbgl/test/stub_file_source.hpp
+++ b/test/src/mbgl/test/stub_file_source.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/storage/file_source.hpp>
+#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/util/timer.hpp>
#include <unordered_map>
@@ -37,6 +38,8 @@ public:
ResponseFunction imageResponse;
private:
+ friend class StubOnlineFileSource;
+
// The default behavior is to throw if no per-kind callback has been set.
optional<Response> defaultResponse(const Resource&);
@@ -45,4 +48,15 @@ private:
util::Timer timer;
};
+class StubOnlineFileSource : public StubFileSource, public OnlineFileSource {
+public:
+
+ StubOnlineFileSource(ResponseType t = ResponseType::Asynchronous) : StubFileSource(t) {};
+ ~StubOnlineFileSource() override = default;
+
+ std::unique_ptr<AsyncRequest> request(const Resource& r, Callback c) override { return StubFileSource::request(r, c); };
+ void remove(AsyncRequest* r) { StubFileSource::remove(r); };
+};
+
+
} // namespace mbgl
diff --git a/test/storage/offline_download.test.cpp b/test/storage/offline_download.test.cpp
index 4db807a204..83fb7f3c18 100644
--- a/test/storage/offline_download.test.cpp
+++ b/test/storage/offline_download.test.cpp
@@ -61,7 +61,7 @@ public:
}
util::RunLoop loop;
- StubFileSource fileSource;
+ StubOnlineFileSource fileSource;
OfflineDatabase db;
std::size_t size = 0;
@@ -277,8 +277,8 @@ TEST(OfflineDownload, Activate) {
}
TEST(OfflineDownload, DoesNotFloodTheFileSourceWithRequests) {
- FakeFileSource fileSource;
OfflineTest test;
+ FakeOnlineFileSource fileSource;
auto region = test.createRegion();
ASSERT_TRUE(region);
OfflineDownload download(
@@ -297,7 +297,7 @@ TEST(OfflineDownload, DoesNotFloodTheFileSourceWithRequests) {
fileSource.respond(Resource::Kind::Style, test.response("style.json"));
test.loop.runOnce();
- EXPECT_EQ(HTTPFileSource::maximumConcurrentRequests(), fileSource.requests.size());
+ EXPECT_EQ(fileSource.getMaximumConcurrentRequests(), fileSource.requests.size());
}
TEST(OfflineDownload, GetStatusNoResources) {
diff --git a/test/storage/online_file_source.test.cpp b/test/storage/online_file_source.test.cpp
index 36d6f63a77..756a7a92d1 100644
--- a/test/storage/online_file_source.test.cpp
+++ b/test/storage/online_file_source.test.cpp
@@ -517,6 +517,15 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(LowHighPriorityRequestsMany)) {
loop.run();
}
+TEST(OnlineFileSource, TEST_REQUIRES_SERVER(MaximumConcurrentRequests)) {
+ util::RunLoop loop;
+ OnlineFileSource fs;
+
+ ASSERT_EQ(fs.getMaximumConcurrentRequests(), 20u);
+
+ fs.setMaximumConcurrentRequests(10);
+ ASSERT_EQ(fs.getMaximumConcurrentRequests(), 10u);
+}
TEST(OnlineFileSource, TEST_REQUIRES_SERVER(RequestSameUrlMultipleTimes)) {
util::RunLoop loop;
OnlineFileSource fs;