summaryrefslogtreecommitdiff
path: root/test/storage
diff options
context:
space:
mode:
authorHuyen Chau Nguyen <hello@chau-nguyen.de>2018-10-17 20:12:28 +0200
committerHuyen Chau Nguyen <hello@chau-nguyen.de>2018-10-23 12:47:10 +0200
commit1e3a744d2296feb2fd6b5d7da324bb31b6ee17c6 (patch)
tree1d3f1975ba993fc4b03caf649190d501eb9e5d41 /test/storage
parent9afe75aa76c02db21209e8f92b09be4b596a3983 (diff)
downloadqtlocation-mapboxgl-1e3a744d2296feb2fd6b5d7da324bb31b6ee17c6.tar.gz
[core] add priorities to resources
- priorities can be low or regular - offline downloads should have low priority to not throttle "regular requests"
Diffstat (limited to 'test/storage')
-rw-r--r--test/storage/default_file_source.test.cpp6
-rw-r--r--test/storage/offline_download.test.cpp60
2 files changed, 63 insertions, 3 deletions
diff --git a/test/storage/default_file_source.test.cpp b/test/storage/default_file_source.test.cpp
index c11d442270..e1c5df6895 100644
--- a/test/storage/default_file_source.test.cpp
+++ b/test/storage/default_file_source.test.cpp
@@ -251,7 +251,7 @@ TEST(DefaultFileSource, OptionalNonExpired) {
util::RunLoop loop;
DefaultFileSource fs(":memory:", ".");
- const Resource optionalResource { Resource::Unknown, "http://127.0.0.1:3000/test", {}, Resource::LoadingMethod::CacheOnly };
+ const Resource optionalResource { Resource::Unknown, "http://127.0.0.1:3000/test", Resource::Priority::Regular, {}, Resource::LoadingMethod::CacheOnly };
using namespace std::chrono_literals;
@@ -281,7 +281,7 @@ TEST(DefaultFileSource, OptionalExpired) {
util::RunLoop loop;
DefaultFileSource fs(":memory:", ".");
- const Resource optionalResource { Resource::Unknown, "http://127.0.0.1:3000/test", {}, Resource::LoadingMethod::CacheOnly };
+ const Resource optionalResource { Resource::Unknown, "http://127.0.0.1:3000/test", Resource::Priority::Regular, {}, Resource::LoadingMethod::CacheOnly };
using namespace std::chrono_literals;
@@ -327,7 +327,7 @@ TEST(DefaultFileSource, OptionalNotFound) {
util::RunLoop loop;
DefaultFileSource fs(":memory:", ".");
- const Resource optionalResource { Resource::Unknown, "http://127.0.0.1:3000/test", {}, Resource::LoadingMethod::CacheOnly };
+ const Resource optionalResource { Resource::Unknown, "http://127.0.0.1:3000/test", Resource::Priority::Regular, {}, Resource::LoadingMethod::CacheOnly };
using namespace std::chrono_literals;
diff --git a/test/storage/offline_download.test.cpp b/test/storage/offline_download.test.cpp
index 5fc0e752df..01baf29592 100644
--- a/test/storage/offline_download.test.cpp
+++ b/test/storage/offline_download.test.cpp
@@ -662,6 +662,66 @@ TEST(OfflineDownload, Deactivate) {
test.loop.run();
}
+
+TEST(OfflineDownload, LowPriorityRequests) {
+ OfflineTest test;
+ auto region = test.createRegion();
+ ASSERT_TRUE(region);
+ OfflineDownload download(
+ region->getID(),
+ OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0),
+ test.db, test.fileSource);
+
+ test.fileSource.styleResponse = [&] (const Resource& resource) {
+ EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ return test.response("style.json");
+ };
+
+ test.fileSource.spriteImageResponse = [&] (const Resource& resource) {
+ EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ return test.response("sprite.png");
+ };
+
+ test.fileSource.imageResponse = [&] (const Resource& resource) {
+ EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ return test.response("radar.gif");
+ };
+
+ test.fileSource.spriteJSONResponse = [&] (const Resource& resource) {
+ EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ return test.response("sprite.json");
+ };
+
+ test.fileSource.glyphsResponse = [&] (const Resource& resource) {
+ EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ return test.response("glyph.pbf");
+ };
+
+ test.fileSource.sourceResponse = [&] (const Resource& resource) {
+ EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ return test.response("streets.json");
+ };
+
+ test.fileSource.tileResponse = [&] (const Resource& resource) {
+ EXPECT_TRUE(resource.priority == Resource::Priority::Low);
+ return test.response("0-0-0.vector.pbf");
+ };
+
+ auto observer = std::make_unique<MockObserver>();
+
+ observer->statusChangedFn = [&] (OfflineRegionStatus status) {
+ if (status.complete()) {
+ test.loop.stop();
+ }
+ };
+
+ download.setObserver(std::move(observer));
+ download.setState(OfflineRegionDownloadState::Active);
+
+ test.loop.run();
+}
+
+
#ifndef __QT__ // Qt doesn't expose the ability to register virtual file system handlers.
TEST(OfflineDownload, DiskFull) {
FixtureLog log;